1 /*******************************************************************************
2 * Copyright (c) 2007, 2012 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.compressions.impl;
14 import java.nio.ByteBuffer;
17 * @author Tuukka Lehtonen
19 public class Buffers {
21 public static byte[] getInputArray(ByteBuffer buffer) {
22 if (buffer.hasArray())
23 return buffer.array();
24 // Poor performance fallback involving copying.
25 byte[] copy = new byte[buffer.remaining()];
30 public static byte[] getOutputArray(ByteBuffer buffer) {
31 return buffer.hasArray() ? buffer.array() : new byte[buffer.remaining()];
34 public static void writeOutput(ByteBuffer buffer, byte[] array) {
35 if (buffer.hasArray() && buffer.array() == array)
37 // Poor performance fallback involving copying.
38 int pos = buffer.position();