List of usage examples for org.apache.commons.io.output CountingOutputStream CountingOutputStream
public CountingOutputStream(OutputStream out)
From source file:com.discursive.jccook.io.CountingOutExample.java
public void start() { File test = new File("test.dat"); CountingOutputStream countStream = null; try {/*from w ww.ja va 2 s. c om*/ FileOutputStream fos = new FileOutputStream(test); countStream = new CountingOutputStream(fos); countStream.write("Hello".getBytes()); } catch (IOException ioe) { System.out.println("Error writing bytes to file."); } finally { IOUtils.closeQuietly(countStream); } if (countStream != null) { int bytesWritten = countStream.getCount(); System.out.println("Wrote " + bytesWritten + " bytes to test.dat"); } }
From source file:com.aliyun.odps.ship.download.TextRecordWriter.java
public TextRecordWriter(File file, String fd, String rd) throws FileNotFoundException { this.os = new CountingOutputStream(new BufferedOutputStream(new FileOutputStream(file), BUFFER_SIZE)); this.fd = fd.getBytes(); this.rd = rd.getBytes(); }
From source file:com.seven.designbox.designpatterns.patterns.proxy.download.StreamCopyUtils.java
public static void copy(InputStream from, OutputStream to, final Listener listener) throws IOException { if (listener == null) { throw new IllegalArgumentException( "listener should not be null, if you don't want listener, use @copy(in,out) one"); }/*w ww . j av a 2 s . c o m*/ IOUtils.copyLarge(from, new CountingOutputStream(to) { @Override protected void afterWrite(int n) throws IOException { super.afterWrite(n); listener.onBytesCopied(getByteCount()); } }, BUFFER_SIZE); }
From source file:com.ooxx.mqtt.internal.wire.MqttOutputStream.java
public MqttOutputStream(ClientState clientState, OutputStream out) { this.clientState = clientState; this.out = new CountingOutputStream(new BufferedOutputStream(out)); }
From source file:com.izforge.izpack.core.io.ByteCountingOutputStream.java
void setOutputStream(OutputStream out) { os = new CountingOutputStream(out); }
From source file:com.nextdoor.bender.ipc.s3.S3TransportBuffer.java
public S3TransportBuffer(long maxBytes, boolean useCompression, S3TransportSerializer serializer) throws TransportException { this.maxBytes = maxBytes; this.serializer = serializer; baos = new ByteArrayOutputStream(); cos = new CountingOutputStream(baos); if (useCompression) { this.isCompressed = true; try {/*w w w . java 2 s . c o m*/ os = new BZip2CompressorOutputStream(cos); } catch (IOException e) { throw new TransportException("unable to create BZip2CompressorOutputStream", e); } } else { this.isCompressed = false; os = cos; } }
From source file:com.github.neoio.net.message.staging.memory.MemoryMessageStaging.java
MemoryMessageStaging() {
logger.debug("creating memory message staging");
this.primaryStage = new ByteArrayOutputStream();
this.readTempStage = new ByteArrayOutputStream();
this.writeTempStage = new ByteArrayOutputStream();
this.readTempStageCount = new CountingOutputStream(readTempStage);
this.writeTempStageCount = new CountingOutputStream(writeTempStage);
}
From source file:eu.delving.sip.files.ReportWriter.java
public ReportWriter(File reportFile, File reportIndexFile, LinkCheckExtractor linkCheckExtractor) throws FileNotFoundException, XPathExpressionException, UnsupportedEncodingException { this.reportFile = reportFile; this.reportIndexFile = reportIndexFile; this.linkCheckExtractor = linkCheckExtractor; this.indexOut = new DataOutputStream(new FileOutputStream(reportIndexFile)); this.count = new CountingOutputStream(new FileOutputStream(reportFile)); this.out = new OutputStreamWriter(count, "UTF-8"); }
From source file:fm.last.moji.impl.FileUploadOutputStream.java
FileUploadOutputStream(TrackerFactory trackerFactory, HttpConnectionFactory httpFactory, String key,
String domain, Destination destination, Lock writeLock) throws IOException {
this.destination = destination;
this.trackerFactory = trackerFactory;
this.domain = domain;
this.key = key;
this.writeLock = writeLock;
log.debug("HTTP PUT -> opening chunked stream -> {}", destination.getPath());
httpConnection = httpFactory.newConnection(destination.getPath());
httpConnection.setRequestMethod("PUT");
httpConnection.setChunkedStreamingMode(CHUNK_LENGTH);
httpConnection.setDoOutput(true);//from w ww. j ava 2s .c o m
delegate = new CountingOutputStream(httpConnection.getOutputStream());
}
From source file:com.loadtesting.showcase.springmvc.filter.PatternFilter.java
/** * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain) */// www . ja v a 2 s . c o m public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { ExampleKpiCapturers caps = new ExampleKpiCapturers(request, PatternLayer.list()); WebProfilingFormat webFormat; try { caps.startDefaultCapturer(); CountingOutputStream cos = new CountingOutputStream(response.getOutputStream()); chain.doFilter(request, response); webFormat = new WebProfilingFormat(request.getContentLength(), cos.getByteCount()); } finally { caps.endDefaultCapturer(); } sendReports(webFormat, caps); }