public CryptoFSDataOutputStream(FSDataOutputStream out, CryptoCodec codec, int bufferSize, byte[] key, byte[] iv, boolean closeOutputStream) throws IOException { super(new CryptoOutputStream(out, codec, bufferSize, key, iv, out.getPos(), closeOutputStream), null, out.getPos()); this.fsOut = out; }
@Override public void hflush() throws IOException { flush(); if (out instanceof Syncable) { ((Syncable)out).hflush(); } }
@Override public void write(int b) throws IOException { oneByteBuf[0] = (byte)(b & 0xff); write(oneByteBuf, 0, oneByteBuf.length); }
@Override public synchronized void close() throws IOException { if (closed) { return; } try { flush(); if (closeOutputStream) { super.close(); codec.close(); } freeBuffers(); } finally { closed = true; } }
checkStream(); if (b == null) { throw new NullPointerException(); off += remaining; len -= remaining; encrypt();
final byte[] tmp = getTmpBuf(); outBuffer.get(tmp, 0, len); out.write(tmp, 0, len); updateEncryptor();
CryptoOutputStream out = new CryptoOutputStream(encryptedDataBuffer, encCodec, bufferSize, key, iv); out.write(data.getData(), 0, data.getLength()); out.flush(); out.close(); LOG.info("Finished encrypting data");
/** * Sync buffered data to DataNodes (flush to disk devices). * * @param syncFlags * Indicate the detailed semantic and actions of the hsync. * @throws IOException * @see FSDataOutputStream#hsync() */ public void hsync(EnumSet<SyncFlag> syncFlags) throws IOException { OutputStream wrappedStream = getWrappedStream(); if (wrappedStream instanceof CryptoOutputStream) { ((CryptoOutputStream) wrappedStream).flush(); wrappedStream = ((CryptoOutputStream) wrappedStream).getWrappedStream(); } ((DFSOutputStream) wrappedStream).hsync(syncFlags); }
public CryptoOutputStream(OutputStream out, CryptoCodec codec, int bufferSize, byte[] key, byte[] iv, long streamOffset, boolean closeOutputStream) throws IOException { super(out); CryptoStreamUtils.checkCodec(codec); this.bufferSize = CryptoStreamUtils.checkBufferSize(codec, bufferSize); this.codec = codec; this.key = key.clone(); this.initIV = iv.clone(); this.iv = iv.clone(); inBuffer = ByteBuffer.allocateDirect(this.bufferSize); outBuffer = ByteBuffer.allocateDirect(this.bufferSize); this.streamOffset = streamOffset; this.closeOutputStream = closeOutputStream; try { encryptor = codec.createEncryptor(); } catch (GeneralSecurityException e) { throw new IOException(e); } updateEncryptor(); }
@Override public synchronized void close() throws IOException { if (closed) { return; } try { super.close(); freeBuffers(); } finally { closed = true; } }
@Override @Deprecated public void sync() throws IOException { hflush(); }
/** * To flush, we need to encrypt the data in the buffer and write to the * underlying stream, then do the flush. */ @Override public synchronized void flush() throws IOException { if (closed) { return; } encrypt(); super.flush(); }
CryptoOutputStream out = new CryptoOutputStream(encryptedDataBuffer, encCodec, bufferSize, key, iv); out.write(data.getData(), 0, data.getLength()); out.flush(); out.close(); LOG.info("Finished encrypting data");
/** * To flush, we need to encrypt the data in the buffer and write to the * underlying stream, then do the flush. */ @Override public synchronized void flush() throws IOException { checkStream(); encrypt(); super.flush(); }
final byte[] tmp = getTmpBuf(); outBuffer.get(tmp, 0, len); out.write(tmp, 0, len); updateEncryptor();
/** * Sync buffered data to DataNodes (flush to disk devices). * * @param syncFlags * Indicate the detailed semantic and actions of the hsync. * @throws IOException * @see FSDataOutputStream#hsync() */ public void hsync(EnumSet<SyncFlag> syncFlags) throws IOException { OutputStream wrappedStream = getWrappedStream(); if (wrappedStream instanceof CryptoOutputStream) { ((CryptoOutputStream) wrappedStream).flush(); wrappedStream = ((CryptoOutputStream) wrappedStream).getWrappedStream(); } ((DFSOutputStream) wrappedStream).hsync(syncFlags); }
public CryptoOutputStream(OutputStream out, CryptoCodec codec, int bufferSize, byte[] key, byte[] iv, long streamOffset) throws IOException { super(out); CryptoStreamUtils.checkCodec(codec); this.bufferSize = CryptoStreamUtils.checkBufferSize(codec, bufferSize); this.codec = codec; this.key = key.clone(); this.initIV = iv.clone(); this.iv = iv.clone(); inBuffer = ByteBuffer.allocateDirect(this.bufferSize); outBuffer = ByteBuffer.allocateDirect(this.bufferSize); this.streamOffset = streamOffset; try { encryptor = codec.createEncryptor(); } catch (GeneralSecurityException e) { throw new IOException(e); } updateEncryptor(); }
@Override public synchronized void close() throws IOException { if (closed) { return; } try { super.close(); freeBuffers(); } finally { closed = true; } }
@Override @Deprecated public void sync() throws IOException { hflush(); }
public CryptoFSDataOutputStream(FSDataOutputStream out, CryptoCodec codec, byte[] key, byte[] iv) throws IOException { super(new CryptoOutputStream(out, codec, key, iv, out.getPos()), null, out.getPos()); this.fsOut = out; }