/** * Return the length of the data. */ long dataSize() { return bucket.size(); }
public AllDataMessage(Bucket bucket, String identifier, boolean global, long startupTime, long completionTime, String mimeType) { this.bucket = bucket; this.dataLength = bucket.size(); this.identifier = identifier; this.global = global; this.startupTime = startupTime; this.completionTime = completionTime; this.mimeType = mimeType; }
public FilterResultMessage(String identifier, String charset, String mimeType, boolean unsafeContentType, Bucket bucket) { this.identifier = identifier; this.charset = charset; this.mimeType = mimeType; this.unsafeContentType = unsafeContentType; if (unsafeContentType) { this.dataLength = -1; } else { this.dataLength = bucket.size(); this.bucket = bucket; } }
@Override public long size() { return bucket.size(); }
@Override public long size() { return proxy.size(); }
@Override public long dataLength() { int dataLength = 0; for(Bucket bucket : buckets.values()) dataLength += bucket.size(); return dataLength; }
@Override protected void freeData() { Bucket d; synchronized(this) { d = data; data = null; if(d == null) return; finishedSize = d.size(); } d.free(); }
public static boolean equalBuckets(Bucket a, Bucket b) throws IOException { if(a.size() != b.size()) return false; long size = a.size(); InputStream aIn = null, bIn = null; try { aIn = a.getInputStreamUnbuffered(); bIn = b.getInputStreamUnbuffered(); return FileUtil.equalStreams(aIn, bIn, size); } finally { aIn.close(); bIn.close(); } }
@Override public byte[] getPartAsBytesThrowing(String name, int maxLength) throws NoSuchElementException, SizeLimitExceededException { if(freedParts) throw new IllegalStateException("Already freed"); Bucket part = this.parts.get(name); if(part == null) throw new NoSuchElementException(name); if(part.size() > maxLength) throw new SizeLimitExceededException(); return getPartAsLimitedBytes(part, maxLength); }
@Override public String getPartAsStringThrowing(String name, int maxLength) throws NoSuchElementException, SizeLimitExceededException { if(freedParts) throw new IllegalStateException("Already freed"); Bucket part = this.parts.get(name); if(part == null) throw new NoSuchElementException(name); if(part.size() > maxLength) throw new SizeLimitExceededException(); return getPartAsLimitedString(part, maxLength); }
@Override protected void writeData(OutputStream os) throws IOException { for(Map.Entry<String, Bucket> entry : buckets.entrySet()) { Bucket bucket = entry.getValue(); BucketTools.copyTo(bucket, os, bucket.size()); if(freeOnSent) bucket.free(); // Always transient so no removeFrom() needed. } }
public freenet.support.api.ManifestElement migrate(BucketFactory bf, ClientContext context) throws ResumeFailedException, IOException { if(data == null) { if(targetURI == null) throw new ResumeFailedException("Must have either a URI or a redirect"); return new freenet.support.api.ManifestElement(name, fullName, mimeOverride, targetURI); } else { if(data.size() != dataSize) throw new ResumeFailedException("Bucket in site insert changed size from "+dataSize+" to "+data.size()); data.onResume(context); RandomAccessBucket convertedData = BucketTools.toRandomAccessBucket(data, bf); return new freenet.support.api.ManifestElement(name, fullName, convertedData, mimeOverride, dataSize); } }
@Override public SimpleFieldSet getFieldSet() { SimpleFieldSet fs = new SimpleFieldSet(true); fs.putSingle("Identifier", identifier); fs.put("Global", global); fs.put("DataLength", data.size()); return fs; }
public static RandomAccessBucket toRandomAccessBucket(Bucket bucket, BucketFactory bf) throws IOException { if(bucket instanceof RandomAccessBucket) return (RandomAccessBucket)bucket; if(bucket instanceof DelayedFreeBucket) { RandomAccessBucket ret = ((DelayedFreeBucket)bucket).toRandomAccessBucket(); if(ret != null) return ret; } RandomAccessBucket ret = bf.makeBucket(bucket.size()); BucketTools.copy(bucket, ret); bucket.free(); return ret; }
/** Checks that the image size calculation works for images with padding */ public void testImageSizeCalculationWithPadding() throws IOException { Bucket input = resourceToBucket("./bmp/sizeCalculationWithPadding.bmp"); Bucket output = filterImage(input, null); //Filter should return the original assertEquals("Input and output should be the same length", input.size(), output.size()); assertTrue("Input and output are not identical", Arrays.equals(BucketTools.toByteArray(input), BucketTools.toByteArray(output))); }
@Override protected void freeBucket(Bucket bucket) throws IOException { File file = ((BaseFileBucket) bucket).getFile(); if (bucket.size() != 0) assertTrue("TempFile not exist", file.exists()); bucket.free(); assertFalse("TempFile not deleted", file.exists()); } }
/** Tests valid image */ public void testValidImage() throws IOException { Bucket input = resourceToBucket("./bmp/ok.bmp"); Bucket output = filterImage(input, null); //Filter should return the original assertEquals("Input and output should be the same length", input.size(), output.size()); assertTrue("Input and output are not identical", Arrays.equals(BucketTools.toByteArray(input), BucketTools.toByteArray(output))); }
/** Checks that the image size calculation works for images without padding */ public void testImageSizeCalculationWithoutPadding() throws IOException { Bucket input = resourceToBucket("./bmp/sizeCalculationWithoutPadding.bmp"); Bucket output = filterImage(input, null); //Filter should return the original assertEquals("Input and output should be the same length", input.size(), output.size()); assertTrue("Input and output are not identical", Arrays.equals(BucketTools.toByteArray(input), BucketTools.toByteArray(output))); }
public void checkSuccessfulRoundTripRandomSplits(int keysize, Random random, Bucket input, Bucket output, Bucket decoded) throws IOException { byte[] key = new byte[keysize]; random.nextBytes(key); OutputStream os = output.getOutputStream(); AEADOutputStream cos = AEADOutputStream.innerCreateAES(os, key, random); BucketTools.copyTo(input, new RandomShortWriteOutputStream(cos, random), -1); cos.close(); assertTrue(output.size() > input.size()); InputStream is = output.getInputStream(); AEADInputStream cis = AEADInputStream.createAES(is, key); BucketTools.copyFrom(decoded, new RandomShortReadInputStream(cis, random), -1); assertEquals(decoded.size(), input.size()); assertTrue(BucketTools.equalBuckets(decoded, input)); }
/** Status. Generally depends on the status of the individual segments... * Not persisted: Can be deduced from the state of the segments, except for the last 3 states, * which are only used during completion (we don't keep the storage around once we're * finished). */ enum Status { NOT_STARTED, STARTED, ENCODED_CROSS_SEGMENTS, ENCODED, GENERATING_METADATA, SUCCEEDED, FAILED }