@Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
@SuppressWarnings({"unchecked"}) private void ensureCapacity(final int len) { if (currentBuffer == null) { currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } else if (currentBuffer.remaining() < len) { if (reallocate) { currentBuffer = mm.reallocate(currentBuffer, Math.max( currentBuffer.capacity() + len, (currentBuffer.capacity() * 3) / 2 + 1)); } else { flushCurrent(); currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { ensureCapacity(len); currentBuffer.put(b, off, len); }
/** * Get the result {@link Buffer} (not flipped). * @return the result {@link Buffer} (not flipped). */ public Buffer getBuffer() { if (reallocate || compositeBuffer == null) { return currentBuffer != null ? currentBuffer : Buffers.EMPTY_BUFFER; } else { if (currentBuffer != null && currentBuffer.position() > 0) { flushCurrent(); } return compositeBuffer; } }
initialBuffer.put(initialBytes); BufferOutputStream bos = new BufferOutputStream(mm, initialBuffer, true); bos.write(b); bos.close(); final Buffer resultBuffer = bos.getBuffer().flip();
public Buffer encode(final MemoryManager mm, final List<String> inputStringList) throws IOException { final String charsetName = charset.name(); final BufferOutputStream baos = new BufferOutputStream(mm, mm.allocate(1024)); final DataOutputStream dos = new DataOutputStream(baos); final Buffer output = baos.getBuffer(); output.trim(); output.allowBufferDispose(true);
// init Persons Persons person = new Persons(); // add some persons.personList.add(new Person()); // write out ObjectOutpuStream oos = new ObjectOutputStream(new BufferOutputStream(new FileOutputStream("personsDB.ser"))); oos.write(persons); oos.close();
@SuppressWarnings({"unchecked"}) private void ensureCapacity(final int len) { if (currentBuffer == null) { currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } else if (currentBuffer.remaining() < len) { if (reallocate) { currentBuffer = mm.reallocate(currentBuffer, Math.max( currentBuffer.capacity() + len, (currentBuffer.capacity() * 3) / 2 + 1)); } else { flushCurrent(); currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } } }
@Override public void write(int b) throws IOException { ensureCapacity(1); currentBuffer.put((byte) b); }
/** * Get the result {@link Buffer} (not flipped). * @return the result {@link Buffer} (not flipped). */ public Buffer getBuffer() { if (reallocate || compositeBuffer == null) { return currentBuffer != null ? currentBuffer : Buffers.EMPTY_BUFFER; } else { if (currentBuffer != null && currentBuffer.position() > 0) { flushCurrent(); } return compositeBuffer; } }
initialBuffer.put(initialBytes); BufferOutputStream bos = new BufferOutputStream(mm, initialBuffer, false); bos.write(b); bos.close(); final Buffer resultBuffer = bos.getBuffer().flip();
@SuppressWarnings({"unchecked"}) private void ensureCapacity(final int len) { if (currentBuffer == null) { currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } else if (currentBuffer.remaining() < len) { if (reallocate) { currentBuffer = mm.reallocate(currentBuffer, Math.max( currentBuffer.capacity() + len, (currentBuffer.capacity() * 3) / 2 + 1)); } else { flushCurrent(); currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } } }
@Override public void write(int b) throws IOException { ensureCapacity(1); currentBuffer.put((byte) b); }
@Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
/** * Get the result {@link Buffer} (not flipped). * @return the result {@link Buffer} (not flipped). */ public Buffer getBuffer() { if (reallocate || compositeBuffer == null) { return currentBuffer != null ? currentBuffer : Buffers.EMPTY_BUFFER; } else { if (currentBuffer != null && currentBuffer.position() > 0) { flushCurrent(); } return compositeBuffer; } }
@SuppressWarnings({"unchecked"}) private void ensureCapacity(final int len) { if (currentBuffer == null) { currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } else if (currentBuffer.remaining() < len) { if (reallocate) { currentBuffer = mm.reallocate(currentBuffer, Math.max( currentBuffer.capacity() + len, (currentBuffer.capacity() * 3) / 2 + 1)); } else { flushCurrent(); currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } } }
@Override public void write(byte[] b, int off, int len) throws IOException { ensureCapacity(len); currentBuffer.put(b, off, len); }
@Override public void write(byte[] b) throws IOException { write(b, 0, b.length); }
/** * Get the result {@link Buffer} (not flipped). * @return the result {@link Buffer} (not flipped). */ public Buffer getBuffer() { if (reallocate || compositeBuffer == null) { return currentBuffer != null ? currentBuffer : Buffers.EMPTY_BUFFER; } else { if (currentBuffer != null && currentBuffer.position() > 0) { flushCurrent(); } return compositeBuffer; } }
@SuppressWarnings({"unchecked"}) private void ensureCapacity(final int len) { if (currentBuffer == null) { currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } else if (currentBuffer.remaining() < len) { if (reallocate) { currentBuffer = mm.reallocate(currentBuffer, Math.max( currentBuffer.capacity() + len, (currentBuffer.capacity() * 3) / 2 + 1)); } else { flushCurrent(); currentBuffer = allocateNewBuffer(mm, Math.max(BUFFER_SIZE, len)); } } }