コード例 #1
0
  /**
   * Write an archive record to the archive, where the record may be inside of a larger array
   * buffer. The buffer must be "offset plus record size" long.
   *
   * @param buf The buffer containing the record data to write.
   * @param offset The offset of the record data within buf.
   * @throws IOException on error
   */
  public void writeRecord(byte[] buf, int offset) throws IOException {
    if (outStream == null) {
      if (inStream == null) {
        throw new IOException("Output buffer is closed");
      }
      throw new IOException("writing to an input buffer");
    }

    if ((offset + recordSize) > buf.length) {
      throw new IOException(
          "record has length '"
              + buf.length
              + "' with offset '"
              + offset
              + "' which is less than the record size of '"
              + recordSize
              + "'");
    }

    if (currRecIdx >= recsPerBlock) {
      writeBlock();
    }

    System.arraycopy(buf, offset, blockBuffer, (currRecIdx * recordSize), recordSize);

    currRecIdx++;
  }
コード例 #2
0
  /**
   * Write an archive record to the archive.
   *
   * @param record The record data to write to the archive.
   * @throws IOException on error
   */
  public void writeRecord(byte[] record) throws IOException {
    if (outStream == null) {
      if (inStream == null) {
        throw new IOException("Output buffer is closed");
      }
      throw new IOException("writing to an input buffer");
    }

    if (record.length != recordSize) {
      throw new IOException(
          "record to write has length '"
              + record.length
              + "' which is not the record size of '"
              + recordSize
              + "'");
    }

    if (currRecIdx >= recsPerBlock) {
      writeBlock();
    }

    System.arraycopy(record, 0, blockBuffer, (currRecIdx * recordSize), recordSize);

    currRecIdx++;
  }
コード例 #3
0
  /** Flush the current data block if it has any data in it. */
  private void flushBlock() throws IOException {
    if (outStream == null) {
      throw new IOException("writing to an input buffer");
    }

    if (currRecIdx > 0) {
      writeBlock();
    }
  }