Package freenet.support.io

Examples of freenet.support.io.ArrayBucketFactory


        if(returnType == ReturnType.DISK) {
            dos.writeUTF(targetFile.toString());
        }
        dos.writeBoolean(binaryBlob);
        DataOutputStream innerDOS =
            new DataOutputStream(checker.checksumWriterWithLength(dos, new ArrayBucketFactory()));       
        try {
            fctx.writeTo(innerDOS);
        } finally {
            innerDOS.close();
        }
        if(extensionCheck != null) {
            dos.writeBoolean(true);
            dos.writeUTF(extensionCheck);
        } else {
            dos.writeBoolean(false);
        }
        if(initialMetadata != null) {
            dos.writeBoolean(true);
            initialMetadata.storeTo(innerDOS);
        } else {
            dos.writeBoolean(false);
        }
        synchronized(this) {
            if(finished) {
                dos.writeBoolean(succeeded);
                writeTransientProgressFields(dos);
                if(succeeded) {
                    if(returnType == ReturnType.DIRECT) {
                        innerDOS =
                            new DataOutputStream(checker.checksumWriterWithLength(dos, new ArrayBucketFactory()));
                        try {
                            returnBucketDirect.storeTo(innerDOS);
                        } finally {
                            innerDOS.close();
                        }
                    }
                } else {
                    innerDOS =
                        new DataOutputStream(checker.checksumWriterWithLength(dos, new ArrayBucketFactory()));
                    try {
                        getFailedMessage.writeTo(innerDOS);
                    } finally {
                        innerDOS.close();
                    }
                }
                return;
            }
        }
        // Not finished, or was recently not finished.
        // Don't hold lock while calling getter.
        // If it's just finished we get a race and restart. That's okay.
        innerDOS =
            new DataOutputStream(checker.checksumWriterWithLength(dos, new ArrayBucketFactory()));
        try {
            if(getter.writeTrivialProgress(innerDOS)) {
                writeTransientProgressFields(innerDOS);
            }
        } finally {
View Full Code Here


      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

public class FetchContextTest extends TestCase {
   
    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);
View Full Code Here

              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;
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

     * @throws CHKDecodeException
     */
  @Override
  public byte[] memoryDecode() throws CHKDecodeException {
    try {
      ArrayBucket a = (ArrayBucket) decode(new ArrayBucketFactory(), 32*1024, false);
      return BucketTools.toByteArray(a); // FIXME
    } catch (IOException e) {
      throw new Error(e);
    }
  }
View Full Code Here

  public void testCompressException() throws IOException {

    byte[] uncompressedData = UNCOMPRESSED_DATA_1.getBytes();
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();

    try {
      Compressor.COMPRESSOR_TYPE.BZIP2.compress(inBucket, factory, 32, 32);
    } catch (CompressionOutputSizeException e) {
      // expect this
View Full Code Here

    return outBuf;
  }

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

    outBucket = Compressor.COMPRESSOR_TYPE.BZIP2.compress(inBucket, factory, 32768, 32768);

    InputStream in = null;
View Full Code Here

  public void testCompressException() throws IOException {

    byte[] uncompressedData = UNCOMPRESSED_DATA_1.getBytes();
    Bucket inBucket = new ArrayBucket(uncompressedData);
    BucketFactory factory = new ArrayBucketFactory();

    try {
      Compressor.COMPRESSOR_TYPE.GZIP.compress(inBucket, factory, 32, 32);
    } catch (CompressionOutputSizeException e) {
      // expect this
View Full Code Here

    return outBuf;
  }

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

    outBucket = Compressor.COMPRESSOR_TYPE.GZIP.compress(inBucket, factory, 32768, 32768);

    InputStream in = null;
View Full Code Here

TOP

Related Classes of freenet.support.io.ArrayBucketFactory

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.