cdm/src/main/java/ucar/unidata/io/RandomAccessFile.java
public void writeBytes(byte b[], int off, int len) throws IOException {
    // If the amount of data is small (less than a full buffer)...
    if (len < buffer.length) {

      // If any of the data fits within the buffer...
      int spaceInBuffer = 0;
      int copyLength = 0;
      if (filePosition >= bufferStart) {
        spaceInBuffer = (int) ((bufferStart + buffer.length) - filePosition);
      }

      if (spaceInBuffer > 0) {
        // Copy as much as possible to the buffer.
        copyLength = (spaceInBuffer > len) ? len : spaceInBuffer;
        System.arraycopy(b, off, buffer, (int) (filePosition - bufferStart), copyLength);
        bufferModified = true;
        long myDataEnd = filePosition + copyLength;
        dataEnd = (myDataEnd > dataEnd) ? myDataEnd : dataEnd;
        dataSize = (int) (dataEnd - bufferStart);
        filePosition += copyLength;
        ///System.out.println("--copy to buffer "+copyLength+" "+len);
      }

      // If there is any data remaining, move to the new position and copy to
      // the new buffer.
      if (copyLength < len) {
        //System.out.println("--need more "+copyLength+" "+len+" space= "+spaceInBuffer);
        seek(filePosition);   // triggers a flush
        System.arraycopy(b, off + copyLength, buffer, (int) (filePosition - bufferStart), len - copyLength);
        bufferModified = true;
        long myDataEnd = filePosition + (len - copyLength);
        dataEnd = (myDataEnd > dataEnd) ? myDataEnd : dataEnd;
        dataSize = (int) (dataEnd - bufferStart);
        filePosition += (len - copyLength);
      }

      // ...or write a lot of data...
    } else {

      // Flush the current buffer, and write this data to the file.
      if (bufferModified) {
        flush();
      }
      file.seek(filePosition);  // moved per Steve Cerruti; Jan 14, 2005
      file.write(b, off, len);
      //System.out.println("--write at "+filePosition+" "+len);

      filePosition += len;
      bufferStart = filePosition;  // an empty buffer
      dataSize = 0;
      dataEnd = bufferStart + dataSize;
    }
  }
public void writeBytes(byte b[], int off, int len) throws IOException {
    // If the amount of data is small (less than a full buffer)...
    if (len < buffer.length) {

      // If any of the data fits within the buffer...
      int spaceInBuffer = 0;
      int copyLength = 0;
      if (filePosition >= bufferStart) {
        spaceInBuffer = (int) ((bufferStart + buffer.length) - filePosition);
      }

      if (spaceInBuffer > 0) {
        // Copy as much as possible to the buffer.
        copyLength = (spaceInBuffer > len) ? len : spaceInBuffer;
        System.arraycopy(b, off, buffer, (int) (filePosition - bufferStart), copyLength);
        bufferModified = true;
        long myDataEnd = filePosition + copyLength;
        dataEnd = (myDataEnd > dataEnd) ? myDataEnd : dataEnd;
        dataSize = (int) (dataEnd - bufferStart);
        filePosition += copyLength;
        ///System.out.println("--copy to buffer "+copyLength+" "+len);
      }

      // If there is any data remaining, move to the new position and copy to
      // the new buffer.
      if (copyLength < len) {
        //System.out.println("--need more "+copyLength+" "+len+" space= "+spaceInBuffer);
        seek(filePosition);   // triggers a flush
        System.arraycopy(b, off + copyLength, buffer, (int) (filePosition - bufferStart), len - copyLength);
        bufferModified = true;
        long myDataEnd = filePosition + (len - copyLength);
        dataEnd = (myDataEnd > dataEnd) ? myDataEnd : dataEnd;
        dataSize = (int) (dataEnd - bufferStart);
        filePosition += (len - copyLength);
      }

      // ...or write a lot of data...
    } else {

      // Flush the current buffer, and write this data to the file.
      if (bufferModified) {
        flush();
      }
      file.seek(filePosition);  // moved per Steve Cerruti; Jan 14, 2005
      file.write(b, off, len);
      //System.out.println("--write at "+filePosition+" "+len);

      filePosition += len;
      bufferStart = filePosition;  // an empty buffer
      dataSize = 0;
      dataEnd = bufferStart + dataSize;
    }
  }
Write <code>len</code> bytes from an array to the file.

@param b   the array containing the data.
@param off the offset in the array to the data.
@param len the length of the data.
@throws IOException if an I/O error occurrs.