Here you can find the source of writeFully(WritableByteChannel bc, ByteBuffer buf)
Parameter | Description |
---|---|
bc | The WritableByteChannel to write to |
buf | The input buffer |
Parameter | Description |
---|---|
IOException | On I/O error |
public static void writeFully(WritableByteChannel bc, ByteBuffer buf) throws IOException
//package com.java2s; //License from project: Apache License import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.WritableByteChannel; public class Main { /**//w w w .j a va 2 s. c o m * Write a ByteBuffer to a WritableByteChannel, handling short writes. * * @param bc The WritableByteChannel to write to * @param buf The input buffer * @throws IOException On I/O error */ public static void writeFully(WritableByteChannel bc, ByteBuffer buf) throws IOException { do { bc.write(buf); } while (buf.remaining() > 0); } /** * Write a ByteBuffer to a FileChannel at a given offset, * handling short writes. * * @param fc The FileChannel to write to * @param buf The input buffer * @param offset The offset in the file to start writing at * @throws IOException On I/O error */ public static void writeFully(FileChannel fc, ByteBuffer buf, long offset) throws IOException { do { offset += fc.write(buf, offset); } while (buf.remaining() > 0); } }