Пример #1
0
  private void serializeFile(DataOutput out, Data value) throws IOException, FileNotFoundException {
    Number160 hash = value.hash();
    // store file name
    out.write(hash.toByteArray());
    // store as external file, create path
    RandomAccessFile file = null;
    FileChannel rwChannel = null;
    try {
      file = new RandomAccessFile(new File(path, hash.toString()), "rw");
      rwChannel = file.getChannel();
      AlternativeCompositeByteBuf acb = AlternativeCompositeByteBuf.compBuffer();
      // store data to disk
      // header first
      value.encodeHeader(acb, signatureFactory);
      rwChannel.write(acb.nioBuffers());
      // next data - no need to copy to another buffer, just take the
      // data from memory
      rwChannel.write(value.toByteBuffers());
      // rest
      try {
        value.encodeDone(acb, signatureFactory);
        rwChannel.write(acb.nioBuffers());
      } catch (InvalidKeyException e) {
        throw new IOException(e);
      } catch (SignatureException e) {
        throw new IOException(e);
      }
    } finally {

      if (rwChannel != null) {
        rwChannel.close();
      }
      if (file != null) {
        file.close();
      }
    }
  }
Пример #2
0
 private void serializeMapDB(DataOutput out, Data value) throws IOException {
   AlternativeCompositeByteBuf acb = AlternativeCompositeByteBuf.compBuffer();
   // store data to disk
   // header first
   value.encodeHeader(acb, signatureFactory);
   write(out, acb.nioBuffers());
   acb.skipBytes(acb.writerIndex());
   // next data - no need to copy to another buffer, just take the data
   // from memory
   write(out, value.toByteBuffers());
   // rest
   try {
     value.encodeDone(acb, signatureFactory);
     write(out, acb.nioBuffers());
   } catch (InvalidKeyException e) {
     throw new IOException(e);
   } catch (SignatureException e) {
     throw new IOException(e);
   }
 }