Package freenet.support.io

Examples of freenet.support.io.ArrayBucket


    super(header, shortText, text, priorityClass, updatedTime, sourceNodeName, composed, sent, received);
    this.URI = URI;
    final Bucket descriptionBucket;
    try {
      if(description != null)
        descriptionBucket = new ArrayBucket(description.getBytes("UTF-8"));
      else
        descriptionBucket = new NullBucket();
    } catch (UnsupportedEncodingException e) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
    }
View Full Code Here


      this.priorityClass = priorityClass;
      this.updatedTime = updatedTime;

      //The text may contain newlines
      try {
        Bucket textBucket = new ArrayBucket(text.getBytes("UTF-8"));
        buckets.put("Text", textBucket);
      } catch (UnsupportedEncodingException e) {
        throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
      }
  }
View Full Code Here

    this.URI = URI;
    this.hasAnActivelink = hasAnActivelink;
    final Bucket descriptionBucket;
    try {
      if(description != null)
        descriptionBucket = new ArrayBucket(description.getBytes("UTF-8"));
      else
        descriptionBucket = new NullBucket();
    } catch (UnsupportedEncodingException e) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
    }
View Full Code Here

      String messageText) {
    super(header, shortText, text, priorityClass, updatedTime, sourceNodeName, composed, sent, received);
    final Bucket messageTextBucket;
    try {
      if(messageText != null)
        messageTextBucket = new ArrayBucket(messageText.getBytes("UTF-8"));
      else
        messageTextBucket = new NullBucket();
    } catch (UnsupportedEncodingException e) {
      throw new Error("Impossible: JVM doesn't support UTF-8: " + e, e);
    }
View Full Code Here

  }

  public void start(boolean aggressive) {
    start(aggressive, true);
    if(blobFile.exists()) {
      ArrayBucket bucket = new ArrayBucket();
      try {
        BucketTools.copy(new FileBucket(blobFile, true, false, false, true), bucket);
        // Allow to free if bogus.
        manager.uom.processRevocationBlob(bucket, "disk", true);
      } catch (IOException e) {
View Full Code Here

          // Client startup may not have completed yet.
          manager.node.clientCore.getPersistentTempDir().mkdirs();
          cg = revocationGetter = new ClientGetter(this,
              manager.getRevocationURI(), ctxRevocation,
              aggressive ? RequestStarter.MAXIMUM_PRIORITY_CLASS : RequestStarter.IMMEDIATE_SPLITFILE_PRIORITY_CLASS,
              null, new BinaryBlobWriter(new ArrayBucket()), null);
          if(logMINOR) Logger.minor(this, "Queued another revocation fetcher (count="+revocationDNFCounter+")");
        }
      }
      if(toCancel != null)
        toCancel.cancel(core.clientContext);
View Full Code Here

        if(tmpBlob == blobBucket) return;
        blobBucket = (ArrayBucket) tmpBlob;
      }
    } else {
      try {
        ArrayBucket buf = new ArrayBucket(BucketTools.toByteArray(tmpBlob));
        synchronized(this) {
          blobBucket = buf;
        }
      } catch (IOException e) {
        System.err.println("Unable to copy data from revocation bucket!");
View Full Code Here

    public void testCopyBucketNotDivisibleBy16() throws IOException {
        checkCopyBucketNotDivisibleBy16(902);
    }

    public void checkCopyBucketNotDivisibleBy16(long length) throws IOException {
        ArrayBucket underlying = new ArrayBucket();
        byte[] key = new byte[16];
        AEADCryptBucket encryptedBucket = new AEADCryptBucket(underlying, key);
        BucketTools.fill(encryptedBucket, length);
        assertEquals(length + AEADCryptBucket.OVERHEAD, underlying.size());
        assertEquals(length, encryptedBucket.size());
        ArrayBucket copyTo = new ArrayBucket();
        BucketTools.copy(encryptedBucket, copyTo);
        assertEquals(length, encryptedBucket.size());
        assertEquals(length, copyTo.size());
        assertTrue(BucketTools.equalBuckets(encryptedBucket, copyTo));
    }
View Full Code Here

  private void checkBlock(byte[] data, boolean newAlgo) throws CHKEncodeException, InvalidCompressionCodecException, CHKVerifyException, CHKDecodeException, IOException {
    byte cryptoAlgorithm = newAlgo ? Key.ALGO_AES_CTR_256_SHA256 : Key.ALGO_AES_PCFB_256_SHA256;
    byte[] copyOfData = new byte[data.length];
    System.arraycopy(data, 0, copyOfData, 0, data.length);
    ClientCHKBlock encodedBlock =
      ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm);
    // Not modified in-place.
    assert(Arrays.equals(data, copyOfData));
    ClientCHK key = encodedBlock.getClientKey();
    if(newAlgo) {
      // Check with no JCA.
      ClientCHKBlock otherEncodedBlock =
        ClientCHKBlock.encode(new ArrayBucket(data), false, false, (short)-1, data.length, null, false, null, cryptoAlgorithm, true);
      assertTrue(key.equals(otherEncodedBlock.getClientKey()));
      assertTrue(Arrays.equals(otherEncodedBlock.getBlock().data, encodedBlock.getBlock().data));
      assertTrue(Arrays.equals(otherEncodedBlock.getBlock().headers, encodedBlock.getBlock().headers));
    }
    // Verify it.
    CHKBlock block = CHKBlock.construct(encodedBlock.getBlock().data, encodedBlock.getBlock().headers, cryptoAlgorithm);
    ClientCHKBlock checkBlock = new ClientCHKBlock(block, key);
    ArrayBucket checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false);
    assert(Arrays.equals(checkData.toByteArray(), data));
    if(newAlgo) {
      checkData = (ArrayBucket) checkBlock.decode(new ArrayBucketFactory(), data.length, false, true);
      assert(Arrays.equals(checkData.toByteArray(), data));
    }
  }
View Full Code Here

        checkSimple(1, 1024);
        checkSimple((1<<17)-1, 1<<17);
    }
   
    public void checkSimple(int length, int expectedLength) throws IOException {
        ArrayBucket input = new ArrayBucket();
        BucketTools.fill(input, length);
        ArrayBucket copy = new ArrayBucket();
        PaddedBucket padded = new PaddedBucket(copy);
        BucketTools.copy(input, padded);
        assertEquals(padded.size(), input.size());
        assertEquals(copy.size(), expectedLength);
        assertTrue(BucketTools.equalBuckets(input, padded));
        InputStream aIn = input.getInputStream();
        InputStream bIn = copy.getInputStream();
        assertTrue(FileUtil.equalStreams(aIn, bIn, length));
    }
View Full Code Here

TOP

Related Classes of freenet.support.io.ArrayBucket

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.