@Override public OutputStream getOutputStreamUnbuffered() throws IOException { return proxy.getOutputStreamUnbuffered(); }
@Override public OutputStream getOutputStreamUnbuffered() throws IOException { synchronized(this) { if(migrated) throw new IOException("Already migrated to a RandomAccessBucket"); if(freed) throw new IOException("Already freed"); } return bucket.getOutputStreamUnbuffered(); }
public static void zeroPad(Bucket b, long size) throws IOException { OutputStream out = b.getOutputStreamUnbuffered(); try { // Initialized to zero by default. byte[] buffer = new byte[16384]; long count = 0; while (count < size) { long nRequired = buffer.length; if (nRequired > size - count) { nRequired = size - count; } out.write(buffer, 0, (int) nRequired); count += nRequired; } } finally { out.close(); } }
/** @deprecated Only for unit tests */ @Deprecated public static void fill(Bucket bucket, Random random, long length) throws IOException { OutputStream os = null; try { os = bucket.getOutputStreamUnbuffered(); FileUtil.fill(os, random, length); } finally { if(os != null) os.close(); } }
/** Fill a bucket with hard to identify random data */ public static void fill(Bucket bucket, long length) throws IOException { OutputStream os = null; try { os = bucket.getOutputStreamUnbuffered(); FileUtil.fill(os, length); } finally { if(os != null) os.close(); } }
@Override public OutputStream getOutputStreamUnbuffered() throws IOException { OutputStream os; synchronized(this) { if(outputStreamOpen) throw new IOException("Already have an OutputStream for "+this); os = underlying.getOutputStreamUnbuffered(); outputStreamOpen = true; size = 0; } return new MyOutputStream(os); }
public OutputStream getOutputStreamUnbuffered() throws IOException { if(readOnly) throw new IOException("Read only"); OutputStream os = bucket.getOutputStreamUnbuffered(); synchronized(this) { dataLength = 0; } return new PaddedEphemerallyEncryptedOutputStream(os, ++lastOutputStream); }
/** Copy data from an InputStream into a Bucket. */ public static void copyFrom(Bucket bucket, InputStream is, long truncateLength) throws IOException { OutputStream os = bucket.getOutputStreamUnbuffered(); byte[] buf = new byte[BUFFER_SIZE]; if(truncateLength < 0) truncateLength = Long.MAX_VALUE; try { long moved = 0; while(moved < truncateLength) { // DO NOT move the (int) inside the Math.min()! big numbers truncate to negative numbers. int bytes = (int) Math.min(buf.length, truncateLength - moved); if(bytes <= 0) throw new IllegalStateException("bytes="+bytes+", truncateLength="+truncateLength+", moved="+moved); bytes = is.read(buf, 0, bytes); if(bytes <= 0) { if(truncateLength == Long.MAX_VALUE) break; IOException ioException = new IOException("Could not move required quantity of data in copyFrom: " + bytes + " (moved " + moved + " of " + truncateLength + "): unable to read from " + is); ioException.printStackTrace(); throw ioException; } os.write(buf, 0, bytes); moved += bytes; } } finally { os.close(); } }
/** * Copy from the input stream of <code>src</code> to the output stream of * <code>dest</code>. * * @param src * @param dst * @throws IOException */ public static void copy(Bucket src, Bucket dst) throws IOException { OutputStream out = dst.getOutputStreamUnbuffered(); InputStream in = src.getInputStreamUnbuffered(); ReadableByteChannel readChannel = Channels.newChannel(in); WritableByteChannel writeChannel = Channels.newChannel(out); try { // No benefit to allocateDirect() as we're wrapping streams anyway, and worse, it'd be a memory leak. ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE); while (readChannel.read(buffer) != -1) { buffer.flip(); while(buffer.hasRemaining()) writeChannel.write(buffer); buffer.clear(); } } finally { writeChannel.close(); readChannel.close(); } }
@Override public OutputStream getOutputStreamUnbuffered() throws IOException { synchronized(this) { if(readOnly) throw new IOException("Read only"); } OutputStream os = underlying.getOutputStreamUnbuffered(); return AEADOutputStream.createAES(os, key, NodeStarter.getGlobalSecureRandom()); }
out = to.getOutputStreamUnbuffered(); byte[] buffer = new byte[16384]; in = from.getInputStreamUnbuffered();
dis.readFully(buf, 0, len); remainingLength -= len; OutputStream os = bucket.getOutputStreamUnbuffered(); try { os.write(buf, 0, len);
Bucket b = bf.makeBucket(blockLength); MersenneTwister mt = new MersenneTwister(hash); OutputStream os = b.getOutputStreamUnbuffered(); try { BucketTools.copyTo(oldBucket, os, length);