Package freenet.support.api

Examples of freenet.support.api.Bucket


      dis = new DataInputStream(is);
      long remainingLength = length;
      byte[] buf = new byte[splitSize];
      for(int i=0;i<bucketCount;i++) {
        int len = (int) Math.min(splitSize, remainingLength);
        Bucket bucket = bf.makeBucket(len);
        buckets[i] = bucket;
        dis.readFully(buf, 0, len);
        remainingLength -= len;
        OutputStream os = bucket.getOutputStreamUnbuffered();
        try {
          os.write(buf, 0, len);
        } finally {
          os.close();
        }
View Full Code Here


   *
   * @return the paded bucket
   */
  public static Bucket pad(Bucket oldBucket, int blockLength, BucketFactory bf, int length) throws IOException {
    byte[] hash = BucketTools.hash(oldBucket);
    Bucket b = bf.makeBucket(blockLength);
    MersenneTwister mt = new MersenneTwister(hash);
    OutputStream os = b.getOutputStreamUnbuffered();
    try {
      BucketTools.copyTo(oldBucket, os, length);
      byte[] buf = new byte[BUFFER_SIZE];
      for(int x=length;x<blockLength;) {
        int remaining = blockLength - x;
        int thisCycle = Math.min(remaining, buf.length);
        mt.nextBytes(buf); // FIXME??
        os.write(buf, 0, thisCycle);
        x += thisCycle;
      }
      os.close();
      os = null;
      if(b.size() != blockLength)
        throw new IllegalStateException("The bucket's size is "+b.size()+" whereas it should be "+blockLength+'!');
      return b;
    } finally { Closer.close(os); }
  }
View Full Code Here

        if(size > maxArchivedFileSize && !name.equals(element)) {
          addErrorElement(ctx, key, name, "File too big: "+size+" greater than current archived file size limit "+maxArchivedFileSize, true);
        } else {
          // Read the element
          long realLen = 0;
          Bucket output = tempBucketFactory.makeBucket(size);
          OutputStream out = output.getOutputStream();

          try {
            int readBytes;
            while((readBytes = tarIS.read(buf)) > 0) {
              out.write(buf, 0, readBytes);
              readBytes += realLen;
              if(readBytes > maxArchivedFileSize) {
                addErrorElement(ctx, key, name, "File too big: "+maxArchivedFileSize+" greater than current archived file size limit "+maxArchivedFileSize, true);
                out.close();
                out = null;
                output.free();
                continue outerTAR;
              }
            }
           
          } finally {
View Full Code Here

 
  static final ArrayBucketFactory ARRAY_FACTORY = new ArrayBucketFactory();
 
    public static byte[] pad(byte[] orig, int blockSize, int length) throws IOException {
        ArrayBucket b = new ArrayBucket(orig);
        Bucket ret = BucketTools.pad(b, blockSize, ARRAY_FACTORY, length);
        return BucketTools.toByteArray(ret);
    }
View Full Code Here

        if(size > maxArchivedFileSize && !name.equals(element)) {
          addErrorElement(ctx, key, name, "File too big: "+maxArchivedFileSize+" greater than current archived file size limit "+maxArchivedFileSize, true);
        } else {
          // Read the element
          long realLen = 0;
          Bucket output = tempBucketFactory.makeBucket(size);
          OutputStream out = output.getOutputStream();
          try {
           
            int readBytes;
            while((readBytes = zis.read(buf)) > 0) {
              out.write(buf, 0, readBytes);
              readBytes += realLen;
              if(readBytes > maxArchivedFileSize) {
                addErrorElement(ctx, key, name, "File too big: "+maxArchivedFileSize+" greater than current archived file size limit "+maxArchivedFileSize, true);
                out.close();
                out = null;
                output.free();
                continue outerZIP;
              }
            }
           
          } finally {
View Full Code Here

    for (String name : names) {
      addToDirectory(dir, name, "");
    }
    Metadata metadata = new Metadata(dir, "");
    int x = 0;
    Bucket bucket = null;
    while(true) {
      try {
        bucket = metadata.toBucket(tempBucketFactory);
        return addStoreElement(ctx, key, ".metadata", bucket, gotElement, element2, callback, context);
      } catch (MetadataUnresolvedException e) {
View Full Code Here

    RealArchiveStoreItem element = new RealArchiveStoreItem(ctx, key, name, temp);
    element.addToContext();
    if(logMINOR) Logger.minor(this, "Adding store element: "+element+" ( "+key+ ' ' +name+" size "+element.spaceUsed()+" )");
    ArchiveStoreItem oldItem;
    // Let it throw, if it does something is drastically wrong
    Bucket matchBucket = null;
    if((!gotElement.value) && name.equals(callbackName)) {
      matchBucket = element.getReaderBucket();
    }
    synchronized (this) {
      oldItem = storedData.get(element.key);
View Full Code Here

            COMPRESSOR_TYPE decompressor = COMPRESSOR_TYPE.getCompressorByMetadataID(compressionAlgorithm);
            if (decompressor==null)
              throw new CHKDecodeException("Unknown compression algorithm: "+compressionAlgorithm);
            InputStream inputStream = null;
            OutputStream outputStream = null;
            Bucket inputBucket = new SimpleReadOnlyArrayBucket(input, inputOffset, inputLength-inputOffset);
            Bucket outputBucket = bf.makeBucket(maxLength);
            outputStream = outputBucket.getOutputStream();
            inputStream = inputBucket.getInputStream();
            try {
              decompressor.decompress(inputStream, outputStream, maxLength, -1);
      catch (CompressionOutputSizeException e) {
        throw new TooBigException("Too big");
View Full Code Here

    private boolean closed;

    /** Create a stream which writes to temporary space and then on a non-aborted close() will
     * write the length (minus the offset) followed by the data. */
    public static PrependLengthOutputStream create(OutputStream out, BucketFactory bf, int offset, boolean closeUnderlying) throws IOException {
        Bucket temp = bf.makeBucket(-1);
        OutputStream os = temp.getOutputStream();
        return new PrependLengthOutputStream(os, temp, out, offset, closeUnderlying);
    }
View Full Code Here

   
    if (certFile.exists()) {
      return new FileInputStream(certFile);
    }
   
    Bucket bucket;
    OutputStream os = null;
   
    try {
      try {
        bucket = new FileBucket(certFile, false, false, false, false);
        os = bucket.getOutputStream();
        writeCerts(os);
        // If this fails, we need the whole fetch to fail.
        os.close(); os = null;
      } finally {
        Closer.close(os);
      }
      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

TOP

Related Classes of freenet.support.api.Bucket

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.