Package freenet.support.io

Examples of freenet.support.io.ArrayBucket


   
    public void testPersistence() throws IOException, StorageFormatException {
        FetchContext context =
            HighLevelSimpleClientImpl.makeDefaultFetchContext(Long.MAX_VALUE, Long.MAX_VALUE,
                    new ArrayBucketFactory(), new SimpleEventProducer());
        ArrayBucket bucket = new ArrayBucket();
        DataOutputStream dos = new DataOutputStream(bucket.getOutputStream());
        context.writeTo(dos);
        dos.close();
        assert(bucket.size() != 0);
        DataInputStream dis = new DataInputStream(bucket.getInputStream());
        FetchContext ctx = new FetchContext(dis);
        dis.close();
        assertTrue(ctx.equals(context));
        bucket.free();
    }
View Full Code Here


 
  public void send(SimpleFieldSet params, byte[] data) throws PluginNotFoundException {
    if (data == null)
      send(params, (Bucket)null);
    else
      send(params, new ArrayBucket(data));
  }
View Full Code Here

        Security.addProvider(new BouncyCastleProvider());
    }
   
    @Override
    protected Bucket makeBucket(long size) throws IOException {
        ArrayBucket underlying = new ArrayBucket();
        return new EncryptedRandomAccessBucket(types[0], underlying, secret);
    }
View Full Code Here

          testKey = new FreenetURI("KSK", dataString);
         
          insertKey = InsertableClientSSK.create(testKey);
          fetchKey = ClientKSK.create(testKey);
         
          block = ((InsertableClientSSK)insertKey).encode(new ArrayBucket(buf), false, false, (short)-1, buf.length, random, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
View Full Code Here

          testKey = new FreenetURI("KSK", keyName);
         
          insertKey = InsertableClientSSK.create(testKey);
          fetchKey = ClientKSK.create(testKey);
         
          block = ((InsertableClientSSK)insertKey).encode(new ArrayBucket(buf), false, false, (short)-1, buf.length, random, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
        } else {
          block = ClientCHKBlock.encode(buf, false, false, (short)-1, buf.length, COMPRESSOR_TYPE.DEFAULT_COMPRESSORDESCRIPTOR, false);
          insertKey = fetchKey = block.getClientKey();
          testKey = insertKey.getURI();
        }
View Full Code Here

          } else {
            if (sourceData.size() > maxCompressedDataLength) {
          // Determine the best algorithm
              COMPRESSOR_TYPE[] comps = COMPRESSOR_TYPE.getCompressorsArray(compressordescriptor, pre1254);
          for (COMPRESSOR_TYPE comp : comps) {
            ArrayBucket compressedData;
            try {
              compressedData = (ArrayBucket) comp.compress(
                  sourceData, new ArrayBucketFactory(), Long.MAX_VALUE, maxCompressedDataLength);
            } catch (CompressionOutputSizeException e) {
              continue;
            }
            if (compressedData.size() <= maxCompressedDataLength) {
              compressionAlgorithm = comp.metadataID;
              sourceLength = sourceData.size();
              try {
                cbuf = BucketTools.toByteArray(compressedData);
                // FIXME provide a method in ArrayBucket
View Full Code Here

      }
      return bucket.getInputStream();
    } catch (IOException e) {
      // We don't have access to TempBucketFactory here.
      // But the certs should be small, so just keep them in memory.
      bucket = new ArrayBucket();
      os = bucket.getOutputStream();
      writeCerts(os);
      os.close();
      return bucket.getInputStream();
    }
View Full Code Here

     * Decode into RAM, if short.
     * @throws KeyDecodeException
     */
  public byte[] memoryDecode(boolean dontDecompress) throws KeyDecodeException {
    try {
      ArrayBucket a = (ArrayBucket) decode(new ArrayBucketFactory(), 32*1024, dontDecompress);
      return BucketTools.toByteArray(a); // FIXME
    } catch (IOException e) {
      throw new Error(e);
    }
  }
View Full Code Here

    assertTrue("Input and output are not identical", Arrays.equals(BucketTools.toByteArray(input), BucketTools.toByteArray(output)));
  }

  private Bucket filterImage(Bucket input, Class<? extends Exception> expected) {
    BMPFilter objBMPFilter = new BMPFilter();
    Bucket output = new ArrayBucket();

    InputStream inStream;
    OutputStream outStream;
    try {
      inStream = input.getInputStream();
      outStream = output.getOutputStream();
    } catch (IOException e) {
      e.printStackTrace();
      fail("Caugth unexpected IOException: " + e);
      return null; //Convince the compiler that we won't continue
    }
View Full Code Here

  }

  private Bucket resourceToBucket(String filename) throws IOException {
    InputStream is = getClass().getResourceAsStream(filename);
    if (is == null) throw new FileNotFoundException();
    Bucket ab = new ArrayBucket();
    BucketTools.copyFrom(ab, is, Long.MAX_VALUE);
    return ab;
  }
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.