Пример #1
0
  public long writeTo(WritableByteChannel channel, long maxBps) throws IOException {
    // format:
    //   <format_version> <sig_len> <sig_data> { <idx_file_name_len> <idx_file_name> <idx_file_len>
    // <idx_file_data> }...

    long amount = 0;

    // format version
    amount += ChannelUtil.writeInt(channel, 1);

    // index signature
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    _sig.save(baos);
    byte[] sigBytes = baos.toByteArray();

    amount += ChannelUtil.writeLong(channel, (long) sigBytes.length); // data length
    amount += channel.write(ByteBuffer.wrap(sigBytes)); // data

    // index files
    Collection<String> fileNames = _snapshot.getFileNames();
    amount += ChannelUtil.writeInt(channel, fileNames.size()); // number of files
    for (String fileName : fileNames) {
      amount += ChannelUtil.writeString(channel, fileName);
      amount += _dirMgr.transferFromFileToChannel(fileName, channel, maxBps);
    }
    return amount;
  }
Пример #2
0
 public void close() {
   _snapshot.close();
 }