/** * Closes the stream and returns the byte array containing the stream's data. * @return The byte array containing the stream's data. * @throws IOException Thrown if the size of the data exceeds the maximal */ public byte[] closeAndGetBytes() throws IOException { if (closed.compareAndSet(false, true)) { checkSize(os.size(), maxSize); byte[] bytes = os.toByteArray(); closeInternal(); return bytes; } else { throw new IOException("stream has already been closed"); } }
/** * Closes the stream and returns the byte array containing the stream's data. * @return The byte array containing the stream's data. * @throws IOException Thrown if the size of the data exceeds the maximal */ public byte[] closeAndGetBytes() throws IOException { if (closed.compareAndSet(false, true)) { checkSize(os.size(), maxSize); byte[] bytes = os.toByteArray(); closeInternal(); return bytes; } else { throw new IOException("stream has already been closed"); } }
/** * Closes the stream and returns the byte array containing the stream's data. * @return The byte array containing the stream's data. * @throws IOException Thrown if the size of the data exceeds the maximal */ public byte[] closeAndGetBytes() throws IOException { if (closed.compareAndSet(false, true)) { checkSize(os.size(), maxSize); byte[] bytes = os.toByteArray(); closeInternal(); return bytes; } else { throw new IOException("stream has already been closed"); } }
/** * Closes the stream and returns the byte array containing the stream's data. * @return The byte array containing the stream's data. * @throws IOException Thrown if the size of the data exceeds the maximal */ public byte[] closeAndGetBytes() throws IOException { if (closed.compareAndSet(false, true)) { checkSize(os.size(), maxSize); byte[] bytes = os.toByteArray(); closeInternal(); return bytes; } else { throw new IOException("stream has already been closed"); } }
/** * Decode a String value. */ public String decodeString(DataInputView source, Order ord) throws IOException { if (reuseBuffer == null) { reuseBuffer = new byte[BUFFER_SIZE]; } if (reuseBaos == null) { reuseBaos = new ByteArrayOutputStreamWithPos(); } reuseBaos.reset(); int len; while ((len = source.read(reuseBuffer)) != -1) { reuseBaos.write(reuseBuffer, 0, len); } if (ord == Order.DESCENDING) { // DESCENDING ordered string requires a termination bit to preserve // sort-order semantics of empty values. reuseBaos.setPosition(reuseBaos.size() - 1); } return new String(ord.apply(reuseBaos.toByteArray()), UTF8); }
/** * Decode a byte array, byte-for-byte copy. */ public byte[] decodeByteArray(DataInputView source, Order ord) throws IOException { if (reuseBuffer == null) { reuseBuffer = new byte[BUFFER_SIZE]; } if (reuseBaos == null) { reuseBaos = new ByteArrayOutputStreamWithPos(); } reuseBaos.reset(); int len; while ((len = source.read(reuseBuffer)) != -1) { reuseBaos.write(reuseBuffer, 0, len); } if (ord == Order.DESCENDING) { // DESCENDING ordered ByteArray requires a termination bit to preserve // sort-order semantics of empty values. reuseBaos.setPosition(reuseBaos.size() - 1); } return ord.apply(reuseBaos.toByteArray()); }
/** * Decode a BinaryString value. */ public BinaryString decodeBinaryString(DataInputView source, Order ord) throws IOException { if (reuseBuffer == null) { reuseBuffer = new byte[BUFFER_SIZE]; } if (reuseBaos == null) { reuseBaos = new ByteArrayOutputStreamWithPos(); } reuseBaos.reset(); int len; while ((len = source.read(reuseBuffer)) != -1) { reuseBaos.write(reuseBuffer, 0, len); } if (ord == Order.DESCENDING) { // DESCENDING ordered string requires a termination bit to preserve // sort-order semantics of empty values. reuseBaos.setPosition(reuseBaos.size() - 1); } return BinaryString.fromBytes(ord.apply(reuseBaos.toByteArray())); }