/** * Write the specified byte. * @param b the byte to be written */ public void write(int b) throws IOException { writeBuffer.put((byte) b); if (writeBuffer.remaining() == 0) { flushInternal(); } position++; }
/** * Write the specified byte. * @param b the byte to be written */ public void write(int b) throws IOException { writeBuffer.put((byte) b); if (writeBuffer.remaining() == 0) { flushInternal(); } position++; }
public void write(byte[] b) throws IOException { int offset = 0; while (offset < b.length) { int toPut = Math.min(b.length - offset, writeBuffer.remaining()); writeBuffer.put(b, offset, toPut); offset += toPut; if (writeBuffer.remaining() == 0) { flushInternal(); } } position += b.length; }
public void write(byte[] b) throws IOException { int offset = 0; while (offset < b.length) { int toPut = Math.min(b.length - offset, writeBuffer.remaining()); writeBuffer.put(b, offset, toPut); offset += toPut; if (writeBuffer.remaining() == 0) { flushInternal(); } } position += b.length; }
/** * Write any data in the buffer to the file. If sync is set to true, force a * sync operation so that data is persisted to the disk. * * @throws IOException if the write or sync operation fails. */ public void flush(boolean shouldForceWrite) throws IOException { synchronized (this) { flushInternal(); } if (shouldForceWrite) { forceWrite(false); } }
/** * Write any data in the buffer to the file. If sync is set to true, force a * sync operation so that data is persisted to the disk. * * @throws IOException if the write or sync operation fails. */ public void flush(boolean shouldForceWrite) throws IOException { synchronized (this) { flushInternal(); } if (shouldForceWrite) { forceWrite(false); } }
/** * Write all the data in src to the {@link FileChannel}. Note that this function can * buffer or re-order writes based on the implementation. These writes will be flushed * to the disk only when flush() is invoked. * * @param src The source ByteBuffer which contains the data to be written. * @throws IOException if a write operation fails. */ public void write(ByteBuffer src) throws IOException { int copied = 0; while (src.remaining() > 0) { int truncated = 0; if (writeBuffer.remaining() < src.remaining()) { truncated = src.remaining() - writeBuffer.remaining(); src.limit(src.limit() - truncated); } copied += src.remaining(); writeBuffer.put(src); src.limit(src.limit() + truncated); // if we have run out of buffer space, we should flush to the file if (writeBuffer.remaining() == 0) { flushInternal(); } } position += copied; }
/** * Write all the data in src to the {@link FileChannel}. Note that this function can * buffer or re-order writes based on the implementation. These writes will be flushed * to the disk only when flush() is invoked. * * @param src The source ByteBuffer which contains the data to be written. * @throws IOException if a write operation fails. */ public void write(ByteBuffer src) throws IOException { int copied = 0; while (src.remaining() > 0) { int truncated = 0; if (writeBuffer.remaining() < src.remaining()) { truncated = src.remaining() - writeBuffer.remaining(); src.limit(src.limit() - truncated); } copied += src.remaining(); writeBuffer.put(src); src.limit(src.limit() + truncated); // if we have run out of buffer space, we should flush to the file if (writeBuffer.remaining() == 0) { flushInternal(); } } position += copied; }