List of usage examples for java.nio.channels Channels newChannel
public static WritableByteChannel newChannel(OutputStream out)
From source file:com.linkedin.databus.core.DbusEventBuffer.java
/** * Injects an event in the regular stream of events * @return true iff successful//w w w . j a va2s . c o m * @throws InvalidEventException */ public boolean injectEvent(DbusEventInternalReadable event) throws InvalidEventException { final ByteBuffer eventBuf = event.getRawBytes(); byte[] cpEventBytes = null; if (eventBuf.hasArray()) { cpEventBytes = eventBuf.array(); } else { cpEventBytes = new byte[event.getRawBytes().limit()]; eventBuf.get(cpEventBytes); } ByteArrayInputStream cpIs = new ByteArrayInputStream(cpEventBytes); ReadableByteChannel cpRbc = Channels.newChannel(cpIs); int ecnt = readEvents(cpRbc); return ecnt > 0; }
From source file:com.sonicle.webtop.mail.Service.java
private void fastStreamCopy(final InputStream src, final OutputStream dest) throws IOException { final ReadableByteChannel in = Channels.newChannel(src); final WritableByteChannel out = Channels.newChannel(dest); fastChannelCopy(in, out);//w ww . j av a 2s .com in.close(); out.close(); }