本文整理汇总了Java中org.apache.commons.io.output.CountingOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java CountingOutputStream类的具体用法?Java CountingOutputStream怎么用?Java CountingOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CountingOutputStream类属于org.apache.commons.io.output包,在下文中一共展示了CountingOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeObject
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/**
* Custom serialization method.
*
* @param oos the object output stream
* @throws IOException
*/
protected void writeObject(ObjectOutputStream oos) throws IOException {
// figure out size of the written network
CountingOutputStream cos = new CountingOutputStream(new NullOutputStream());
if (replaceMissingFilter != null) {
ModelSerializer.writeModel(model, cos, false);
}
modelSize = cos.getByteCount();
// default serialization
oos.defaultWriteObject();
// actually write the network
if (replaceMissingFilter != null) {
ModelSerializer.writeModel(model, oos, false);
}
}
示例2: S3TransportBuffer
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
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 {
os = new BZip2CompressorOutputStream(cos);
} catch (IOException e) {
throw new TransportException("unable to create BZip2CompressorOutputStream", e);
}
} else {
this.isCompressed = false;
os = cos;
}
}
示例3: create_socket_and_listen
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/**
* Establish socket connection with client
*/
private void create_socket_and_listen() throws Exception {
sock = new ServerSocket(EstimateNConfig.socketPort); // create socket and bind to port
System.out.println("waiting for client to connect");
clientSocket = sock.accept(); // wait for client to connect
System.out.println("client has connected");
CountingOutputStream cos = new CountingOutputStream(clientSocket.getOutputStream());
CountingInputStream cis = new CountingInputStream(clientSocket.getInputStream());
ProgCommon.oos = new ObjectOutputStream(cos);
ProgCommon.ois = new ObjectInputStream(cis);
StopWatch.cos = cos;
StopWatch.cis = cis;
}
示例4: encodeAndWriteStream
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/**
* Encodes and writes a stream directly to an OutputStream. The length of
* the stream, in this case, is set on a PDFNumber object that has to be
* prepared beforehand.
* @param out OutputStream to write to
* @param refLength PDFNumber object to receive the stream length
* @return number of bytes written (header and trailer included)
* @throws IOException in case of an I/O problem
*/
protected int encodeAndWriteStream(OutputStream out, PDFNumber refLength)
throws IOException {
int bytesWritten = 0;
//Stream header
byte[] buf = encode("stream\n");
out.write(buf);
bytesWritten += buf.length;
//Stream contents
CloseBlockerOutputStream cbout = new CloseBlockerOutputStream(out);
CountingOutputStream cout = new CountingOutputStream(cbout);
OutputStream filteredOutput = getFilterList().applyFilters(cout);
outputRawStreamData(filteredOutput);
filteredOutput.close();
refLength.setNumber(Integer.valueOf(cout.getCount()));
bytesWritten += cout.getCount();
//Stream trailer
buf = encode("\nendstream");
out.write(buf);
bytesWritten += buf.length;
return bytesWritten;
}
示例5: output
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public int output(OutputStream stream) throws IOException {
CountingOutputStream cout = new CountingOutputStream(stream);
StringBuilder textBuffer = new StringBuilder(64);
textBuffer.append('[');
boolean first = true;
for (Map.Entry<Integer, Object> entry : this.map.entrySet()) {
if (!first) {
textBuffer.append(" ");
}
first = false;
formatObject(entry.getKey(), cout, textBuffer);
textBuffer.append(" ");
formatObject(entry.getValue(), cout, textBuffer);
}
textBuffer.append(']');
PDFDocument.flushTextBuffer(textBuffer, cout);
return cout.getCount();
}
示例6: output
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public int output(OutputStream stream) throws IOException {
CountingOutputStream cout = new CountingOutputStream(stream);
StringBuilder textBuffer = new StringBuilder(64);
textBuffer.append('[');
for (int i = 0; i < values.size(); i++) {
if (i > 0) {
textBuffer.append(' ');
}
Object obj = this.values.get(i);
formatObject(obj, cout, textBuffer);
}
textBuffer.append(']');
PDFDocument.flushTextBuffer(textBuffer, cout);
return cout.getCount();
}
示例7: testOutputInline
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/**
* Test outputInline() - this writes the object reference if it is a direct object (has an
* object number), or writes the String representation if there is no object number.
*/
@Test
public void testOutputInline() {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
CountingOutputStream cout = new CountingOutputStream(outStream);
StringBuilder textBuffer = new StringBuilder();
try {
// test with no object number set.
pdfName.outputInline(outStream, textBuffer);
PDFDocument.flushTextBuffer(textBuffer, cout);
assertEquals("/TestName", outStream.toString());
outStream.reset();
// test with object number set
pdfName.setObjectNumber(1);
pdfName.outputInline(outStream, textBuffer);
PDFDocument.flushTextBuffer(textBuffer, cout);
assertEquals("1 0 R", outStream.toString());
} catch (IOException e) {
fail("IOException: " + e.getMessage());
}
}
示例8: copyData
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
@Override
protected void copyData(InputStream inputStream, OutputStream outputStream) throws IOException {
final CountingOutputStream countingOutputStream = new CountingOutputStream(outputStream);
Timer timer = new Timer();
try {
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
progressListener.updateProgress(countingOutputStream.getCount());
}
}, 0, 50);
super.copyData(inputStream, countingOutputStream);
} finally {
timer.cancel();
}
}
示例9: init
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/**
* Open the file and write its header.
*/
private void init() throws IOException {
FileSystem fs = this.path.getFileSystem(conf);
FSDataOutputStream fsOut = fs.create(this.path);
this.countingOut = new CountingOutputStream(
new BufferedOutputStream(fsOut));
this.out = new DataOutputStream(this.countingOut);
// put any necessary config strings into the header.
MetaBlock m = this.header.getMetaBlock();
if (isCharData) {
m.put(MetaBlock.ENTRY_ENCODING_KEY, MetaBlock.CLOB_ENCODING);
} else {
m.put(MetaBlock.ENTRY_ENCODING_KEY, MetaBlock.BLOB_ENCODING);
}
if (null != codec) {
m.put(MetaBlock.COMPRESSION_CODEC_KEY, this.codecName);
}
// Serialize the value of maxEntriesPerSegment as a VInt in a byte array
// and put that into the metablock as ENTRIES_PER_SEGMENT_KEY.
int segmentBufLen = WritableUtils.getVIntSize(this.maxEntriesPerSegment);
DataOutputBuffer entriesPerSegBuf = new DataOutputBuffer(segmentBufLen);
WritableUtils.writeVInt(entriesPerSegBuf, this.maxEntriesPerSegment);
byte [] entriesPerSegArray =
Arrays.copyOf(entriesPerSegBuf.getData(), segmentBufLen);
m.put(MetaBlock.ENTRIES_PER_SEGMENT_KEY,
new BytesWritable(entriesPerSegArray));
// Write the file header to the file.
this.header.write(out);
// Now we're ready to accept record data from the user.
}
示例10: writeBlobRecord
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
@Override
/**
* {@inheritDoc}
*/
public OutputStream writeBlobRecord(long claimedLen) throws IOException {
finishRecord(); // finish any previous record.
checkForNull(this.out);
startRecordIndex();
this.header.getStartMark().write(out);
LOG.debug("Starting new record; id=" + curEntryId
+ "; claimedLen=" + claimedLen);
WritableUtils.writeVLong(out, curEntryId);
WritableUtils.writeVLong(out, claimedLen);
this.curClaimedLen = claimedLen;
this.userCountingOutputStream = new CountingOutputStream(
new CloseShieldOutputStream(out));
if (null == this.codec) {
// No codec; pass thru the same OutputStream to the user.
this.userOutputStream = this.userCountingOutputStream;
} else {
// Wrap our CountingOutputStream in a compressing OutputStream to
// give to the user.
this.compressor.reset();
this.userOutputStream = new CompressorStream(
this.userCountingOutputStream, compressor);
}
return this.userOutputStream;
}
示例11: openNextFile
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
/** Initialize the OutputStream to the next file to write to.
*/
private void openNextFile() throws IOException {
StringBuffer sb = new StringBuffer();
Formatter fmt = new Formatter(sb);
fmt.format("%05d", this.fileNum++);
String filename = filePrefix + fmt.toString();
if (codec != null) {
filename = filename + codec.getDefaultExtension();
}
Path destFile = new Path(destDir, filename);
FileSystem fs = destFile.getFileSystem(conf);
LOG.debug("Opening next output file: " + destFile);
if (fs.exists(destFile)) {
Path canonicalDest = destFile.makeQualified(fs);
throw new IOException("Destination file " + canonicalDest
+ " already exists");
}
OutputStream fsOut = fs.create(destFile);
// Count how many actual bytes hit HDFS.
this.countingFilterStream = new CountingOutputStream(fsOut);
if (codec != null) {
// Wrap that in a compressing stream.
this.writeStream = codec.createOutputStream(this.countingFilterStream);
} else {
// Write to the counting stream directly.
this.writeStream = this.countingFilterStream;
}
}
示例12: FileHolder
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
public FileHolder() throws IOException {
super();
this.plainTempFile = Files.createTempFile("", "");
this.plainStream = new CountingOutputStream(Files.newOutputStream(plainTempFile));
this.gzTempFile = Files.createTempFile("", "");
this.gzStream = new CountingOutputStream(Files.newOutputStream(gzTempFile));
this.bzTempFile = Files.createTempFile("", "");
this.bzStream = new CountingOutputStream(Files.newOutputStream(bzTempFile));
}
示例13: downloadMethodShouldCreateLocalFileStreamContainingProgressListener
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
@Test
public void downloadMethodShouldCreateLocalFileStreamContainingProgressListener() throws IOException {
FTPFile file = new FTPFile("remote.file", 0l, "path/to", 0, false);
ftpConnection.setProgressListener(new ProgressListener());
ftpConnection.download(file, LOCAL_DIRECTORY);
verify(mockFileStreamFactory).createOutputStream(LOCAL_DIRECTORY + "/remote.file");
verify(mockFtpClient).retrieveFile(eq("path/to/remote.file"), any(CountingOutputStream.class));
}
示例14: getWriter
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
@Override
public FileWriter getWriter(final long bucketKey, final String fileName) throws IOException
{
final DataOutputStream dos = getOutputStream(bucketKey, fileName);
final CountingOutputStream cos = new CountingOutputStream(dos);
final Output out = new Output(cos);
return new FileWriter()
{
@Override
public void close() throws IOException
{
out.close();
cos.close();
dos.close();
}
@Override
public void append(byte[] key, byte[] value) throws IOException
{
kryo.writeObject(out, key);
kryo.writeObject(out, value);
}
@Override
public long getBytesWritten()
{
return cos.getCount() + out.position();
}
};
}
示例15: RecordWriter
import org.apache.commons.io.output.CountingOutputStream; //导入依赖的package包/类
public RecordWriter(Path path, long timeToLiveMillis, OutputStream textOutputStream,
DataGeneratorFactory generatorFactory, StreamCloseEventHandler streamCloseEventHandler) throws StageException, IOException {
this(path, timeToLiveMillis, generatorFactory);
this.textOutputStream = new CountingOutputStream(textOutputStream);
generator = generatorFactory.getGenerator(this.textOutputStream, streamCloseEventHandler);
textFile = true;
this.idleTimeout = -1L;
}