Package freenet.support.api

Examples of freenet.support.api.Bucket


      uncompressedData[i] = 1;
    }

    byte[] compressedData = doCompress(uncompressedData);

    Bucket inBucket = new ArrayBucket(compressedData);
    NullBucket outBucket = new NullBucket();
    InputStream decompressorInput = null;
    OutputStream decompressorOutput = null;

    try {
      decompressorInput = inBucket.getInputStream();
      decompressorOutput = outBucket.getOutputStream();
      Compressor.COMPRESSOR_TYPE.LZMA_NEW.decompress(decompressorInput, decompressorOutput, 4096 + 10, 4096 + 20);
      decompressorInput.close();
      decompressorOutput.close();
    } catch (CompressionOutputSizeException e) {
      // expect this
      return;
    } finally {
      Closer.close(decompressorInput);
      Closer.close(decompressorOutput);
      inBucket.free();
      outBucket.free();
    }
    // TODO LOW codec doesn't actually enforce size limit
    //fail("did not throw expected CompressionOutputSizeException");
  }
View Full Code Here


    // TODO LOW codec doesn't actually enforce size limit
    //fail("did not throw expected CompressionOutputSizeException");
  }

  private byte[] doCompress(byte[] uncompressedData) throws IOException {
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();
    Bucket outBucket = null;

    outBucket = Compressor.COMPRESSOR_TYPE.LZMA_NEW.compress(inBucket, factory, uncompressedData.length, uncompressedData.length * 2 + 64);

    InputStream in = null;
    in = outBucket.getInputStream();
    long size = outBucket.size();
    byte[] outBuf = new byte[(int) size];

    in.read(outBuf);

    return outBuf;
View Full Code Here

  @Override
  public void put(T block, byte[] data, byte[] header, boolean overwrite, boolean isOldBlock) throws IOException, KeyCollisionException {
    byte[] routingkey = block.getRoutingKey();
    byte[] fullKey = block.getFullKey();
   
    Bucket bucket = bf.makeBucket(fullKeySize + dataSize + headerSize);
    OutputStream os = bucket.getOutputStream();
    try {
    os.write(fullKey);
    os.write(header);
    os.write(data);
    } finally {
View Full Code Here

        underlying.free();
    }

    @Override
    public Bucket createShadow() {
        Bucket shadow = underlying.createShadow();
        PaddedBucket ret = new PaddedBucket(shadow, size);
        ret.setReadOnly();
        return ret;
    }
View Full Code Here

        BucketTools.fill(input, 2048);
        int keysize = 16;
        Random random = new Random(0x47f6709f);
        byte[] key = new byte[keysize];
        random.nextBytes(key);
        Bucket output = new ArrayBucket();
        OutputStream os = output.getOutputStream();
        AEADOutputStream cos = AEADOutputStream.innerCreateAES(os, key, random);
        BucketTools.copyTo(input, cos, 2048);
        cos.close();
        InputStream is = output.getInputStream();
        AEADInputStream cis = AEADInputStream.createAES(is, key);
        byte[] first1KReadEncrypted = new byte[1024];
        new DataInputStream(cis).readFully(first1KReadEncrypted);
        byte[] first1KReadOriginal = new byte[1024];
        new DataInputStream(input.getInputStream()).readFully(first1KReadOriginal);
View Full Code Here

        BucketTools.fill(input, 1024);
        int keysize = 16;
        Random random = new Random(0x47f6709f);
        byte[] key = new byte[keysize];
        random.nextBytes(key);
        Bucket output = new ArrayBucket();
        OutputStream os = output.getOutputStream();
        AEADOutputStream cos = AEADOutputStream.innerCreateAES(new NoCloseProxyOutputStream(os), key, random);
        BucketTools.copyTo(input, cos, -1);
        cos.close();
        // Now write garbage.
        FileUtil.fill(os, 1024);
        os.close();
        InputStream is = output.getInputStream();
        AEADInputStream cis = AEADInputStream.createAES(is, key);
        byte[] first1KReadEncrypted = new byte[1024];
        new DataInputStream(cis).readFully(first1KReadEncrypted);
        byte[] first1KReadOriginal = new byte[1024];
        new DataInputStream(input.getInputStream()).readFully(first1KReadOriginal);
View Full Code Here

    saltStore.close();
  }

  private String decodeBlock(CHKBlock verify, ClientCHK key) throws CHKVerifyException, CHKDecodeException, IOException {
    ClientCHKBlock cb = new ClientCHKBlock(verify, key);
    Bucket output = cb.decode(new ArrayBucketFactory(), 32768, false);
    byte[] buf = BucketTools.toByteArray(output);
    return new String(buf, "UTF-8");
  }
View Full Code Here

    assertTrue(false);
  }

  private String decodeBlock(CHKBlock verify, ClientCHK key) throws CHKVerifyException, CHKDecodeException, IOException {
    ClientCHKBlock cb = new ClientCHKBlock(verify, key);
    Bucket output = cb.decode(new ArrayBucketFactory(), 32768, false);
    byte[] buf = BucketTools.toByteArray(output);
    return new String(buf, "UTF-8");
  }
View Full Code Here

      }
    }
   
    /** A blocking method to force-migrate from a RAMBucket to a FileBucket */
    public final boolean migrateToDisk() throws IOException {
      Bucket toMigrate = null;
      long size;
      synchronized(this) {
        if(!isRAMBucket() || hasBeenFreed)
          // Nothing to migrate! We don't want to switch back to ram, do we?         
          return false;
        toMigrate = currentBucket;
        RandomAccessBucket tempFB = _makeFileBucket();
        size = currentSize;
        if(os != null) {
          os.flush();
          os.close();
          // DO NOT INCREMENT THE osIndex HERE!
          os = tempFB.getOutputStreamUnbuffered();
          if(size > 0)
            BucketTools.copyTo(toMigrate, os, size);
        } else {
          if(size > 0) {
            OutputStream temp = tempFB.getOutputStreamUnbuffered();
            try {
            BucketTools.copyTo(toMigrate, temp, size);
            } finally {
            temp.close();
            }
          }
        }
        if(toMigrate.isReadOnly())
          tempFB.setReadOnly();
       
        closeInputStreams(false);
       
        currentBucket = tempFB;
        // We need streams to be reset to point to the new bucket
      }
      if(logMINOR)
        Logger.minor(this, "We have migrated "+toMigrate.hashCode());
     
      synchronized(ramBucketQueue) {
        ramBucketQueue.remove(getReference());
      }
     
      // We can free it on-thread as it's a rambucket
      toMigrate.free();
      // Might have changed already so we can't rely on currentSize!
      _hasFreed(size);
      return true;
    }
View Full Code Here

            System.err.println("Unable to create folder for plugin data: "+pluginStoresDir.dir());
        }
    }

    private void writePluginStoreInner(String storeIdentifier, PluginStore pluginStore, boolean isEncrypted, boolean backup) throws IOException {
        Bucket bucket = makePluginStoreBucket(storeIdentifier, isEncrypted, backup);
        OutputStream os = bucket.getOutputStream();
        try {
            if(pluginStore != null) {
                pluginStore.exportStoreAsSFS().writeTo(os);
            }
        } finally {
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.