Package freenet.support.io

Examples of freenet.support.io.ByteArrayRandomAccessBuffer


  public RandomAccessBuffer getBlobBuffer() {
    if(!manager.isBlown()) return null;
    synchronized(this) {
      if(blobBucket != null) {
          try {
              ByteArrayRandomAccessBuffer t = new ByteArrayRandomAccessBuffer(blobBucket.toByteArray());
              t.setReadOnly();
              return t;
          } catch (IOException e) {
              Logger.error(this, "Impossible: "+e, e);
              return null;
          }
View Full Code Here


   * @param cb
   * @throws NotConnectedException If the peer is not connected, or we lose the connection to the peer,
   * or it restarts.
   */
  private boolean innerSendOpennetRef(long xferUID, byte[] padded, PeerNode peer, ByteCounter ctr, AllSentCallback cb) throws NotConnectedException {
    ByteArrayRandomAccessBuffer raf = new ByteArrayRandomAccessBuffer(padded);
    raf.setReadOnly();
    PartiallyReceivedBulk prb =
      new PartiallyReceivedBulk(node.usm, padded.length, Node.PACKET_SIZE, raf, true);
    try {
      BulkTransmitter bt =
        new BulkTransmitter(prb, peer, xferUID, true, ctr, true, cb);
View Full Code Here

    }
  }

  static byte[] innerWaitForOpennetNoderef(long xferUID, int paddedLength, int realLength, PeerNode source, boolean isReply, long uid, boolean sendReject, ByteCounter ctr, Node node) {
    byte[] buf = new byte[paddedLength];
    ByteArrayRandomAccessBuffer raf = new ByteArrayRandomAccessBuffer(buf);
    PartiallyReceivedBulk prb = new PartiallyReceivedBulk(node.usm, buf.length, Node.PACKET_SIZE, raf, false);
    BulkReceiver br = new BulkReceiver(prb, source, xferUID, ctr);
    if (logMINOR) {
      Logger.minor(OpennetManager.class, "Receiving noderef (reply="+isReply+") as bulk transfer for request uid "+uid+" with transfer "+xferUID+" from "+source);
    }
View Full Code Here

        throw new UnsupportedOperationException();
    }

    @Override
    public LockableRandomAccessBuffer toRandomAccessBuffer() throws IOException {
        ByteArrayRandomAccessBuffer raf = new ByteArrayRandomAccessBuffer(buf, offset, length, true);
        raf.setReadOnly();
        return raf;
    }
View Full Code Here

        super(TEST_LIST);
    }
   
    @Override
    protected RandomAccessBuffer construct(long size) throws IOException {
        ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer((int)(size+types[0].headerLen));
        try {
            return new EncryptedRandomAccessBuffer(types[0], barat, secret, true);
        } catch (GeneralSecurityException e) {
            throw new Error(e);
        }
View Full Code Here

   
    @Test
    public void testSuccesfulRoundTrip() throws IOException, GeneralSecurityException{
        for(EncryptedRandomAccessBufferType type: types){
            byte[] bytes = new byte[100];
            ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer(bytes);
            EncryptedRandomAccessBuffer erat = new EncryptedRandomAccessBuffer(type, barat, secret, true);
            erat.pwrite(0, message, 0, message.length);
            byte[] result = new byte[message.length];
            erat.pread(0, result, 0, result.length);
            erat.close();
View Full Code Here

   
    @Test
    public void testSuccesfulRoundTripReadHeader() throws IOException, GeneralSecurityException{
        for(EncryptedRandomAccessBufferType type: types){
            byte[] bytes = new byte[100];
            ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer(bytes);
            EncryptedRandomAccessBuffer erat = new EncryptedRandomAccessBuffer(type, barat, secret, true);
            erat.pwrite(0, message, 0, message.length);
            erat.close();
            ByteArrayRandomAccessBuffer barat2 = new ByteArrayRandomAccessBuffer(bytes);
            EncryptedRandomAccessBuffer erat2 = new EncryptedRandomAccessBuffer(type, barat2, secret, false);
            byte[] result = new byte[message.length];
            erat2.pread(0, result, 0, result.length);
            erat2.close();
            assertArrayEquals(message, result);
View Full Code Here

    }
   
    @Test
    public void testWrongERATType() throws IOException, GeneralSecurityException {
        byte[] bytes = new byte[100];
        ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer(bytes);
        EncryptedRandomAccessBuffer erat = new EncryptedRandomAccessBuffer(types[0], barat, secret, true);
        erat.close();
        ByteArrayRandomAccessBuffer barat2 = new ByteArrayRandomAccessBuffer(bytes);
        thrown.expect(IOException.class);
        thrown.expectMessage("This is not an EncryptedRandomAccessBuffer"); // Different header lengths.
        EncryptedRandomAccessBuffer erat2 = new EncryptedRandomAccessBuffer(types[1], barat2,
                secret, false);
    }
View Full Code Here

   
    @Test
    public void testUnderlyingRandomAccessThingTooSmall()
            throws GeneralSecurityException, IOException {
        byte[] bytes = new byte[10];
        ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer(bytes);
        thrown.expect(IOException.class);
        thrown.expectMessage("Underlying RandomAccessBuffer is not long enough to include the "
                + "footer.");
        EncryptedRandomAccessBuffer erat = new EncryptedRandomAccessBuffer(types[0], barat, secret, true);
    }
View Full Code Here

    }
   
    @Test
    public void testWrongMagic() throws IOException, GeneralSecurityException{
        byte[] bytes = new byte[100];
        ByteArrayRandomAccessBuffer barat = new ByteArrayRandomAccessBuffer(bytes);
        EncryptedRandomAccessBuffer erat = new EncryptedRandomAccessBuffer(types[0], barat, secret, true);
        erat.close();
        ByteArrayRandomAccessBuffer barat2 = new ByteArrayRandomAccessBuffer(bytes);
        byte[] magic = ByteBuffer.allocate(8).putLong(falseMagic).array();
        barat2.pwrite(types[0].headerLen-8, magic, 0, 8);
        thrown.expect(IOException.class);
        thrown.expectMessage("This is not an EncryptedRandomAccessBuffer!");
        EncryptedRandomAccessBuffer erat2 = new EncryptedRandomAccessBuffer(types[0], barat2, secret, false);
    }
View Full Code Here

TOP

Related Classes of freenet.support.io.ByteArrayRandomAccessBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.