本文整理了Java中org.apache.commons.io.output.ByteArrayOutputStream.toInputStream()
方法的一些代码示例,展示了ByteArrayOutputStream.toInputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteArrayOutputStream.toInputStream()
方法的具体详情如下:
包路径:org.apache.commons.io.output.ByteArrayOutputStream
类名称:ByteArrayOutputStream
方法名:toInputStream
[英]Gets the current contents of this byte stream as a Input Stream. The returned stream is backed by buffers of this
stream, avoiding memory allocation and copy, thus saving space and time.
[中]获取此字节流的当前内容作为输入流。返回的流由this
流的缓冲区支持,避免了内存分配和复制,从而节省了空间和时间。
代码示例来源:origin: commons-io/commons-io
/**
* Fetches entire contents of an <code>InputStream</code> and represent
* same data as result InputStream.
* <p>
* This method is useful where,
* <ul>
* <li>Source InputStream is slow.</li>
* <li>It has network resources associated, so we cannot keep it open for
* long time.</li>
* <li>It has network timeout associated.</li>
* </ul>
* It can be used in favor of {@link #toByteArray()}, since it
* avoids unnecessary allocation and copy of byte[].<br>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input Stream to be fully buffered.
* @param size the initial buffer size
* @return A fully buffered stream.
* @throws IOException if an I/O error occurs
* @since 2.5
*/
public static InputStream toBufferedInputStream(final InputStream input, final int size)
throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
@SuppressWarnings("resource")
final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
output.write(input);
return output.toInputStream();
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testToInputStream() throws IOException {
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final java.io.ByteArrayOutputStream ref = new java.io.ByteArrayOutputStream();
//Write 8224 bytes
writeData(baout, ref, 32);
for(int i=0;i<128;i++) {
writeData(baout, ref, 64);
}
//Get data before more writes
final InputStream in = baout.toInputStream();
byte refData[] = ref.toByteArray();
//Write some more data
writeData(baout, ref, new int[] { 2, 4, 8, 16 });
//Check original data
byte baoutData[] = IOUtils.toByteArray(in);
assertEquals(8224, baoutData.length);
checkByteArrays(refData, baoutData);
//Check all data written
baoutData = IOUtils.toByteArray(baout.toInputStream());
refData = ref.toByteArray();
assertEquals(8254, baoutData.length);
checkByteArrays(refData, baoutData);
baout.close();
in.close();
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testToInputStreamWithReset() throws IOException {
//Make sure reset() do not destroy InputStream returned from toInputStream()
final ByteArrayOutputStream baout = new ByteArrayOutputStream();
final java.io.ByteArrayOutputStream ref = new java.io.ByteArrayOutputStream();
//Write 8224 bytes
writeData(baout, ref, 32);
for(int i=0;i<128;i++) {
writeData(baout, ref, 64);
}
//Get data before reset
final InputStream in = baout.toInputStream();
byte refData[] = ref.toByteArray();
//Reset and write some new data
baout.reset();
ref.reset();
writeData(baout, ref, new int[] { 2, 4, 8, 16 });
//Check original data
byte baoutData[] = IOUtils.toByteArray(in);
assertEquals(8224, baoutData.length);
checkByteArrays(refData, baoutData);
//Check new data written after reset
baoutData = IOUtils.toByteArray(baout.toInputStream());
refData = ref.toByteArray();
assertEquals(30, baoutData.length);
checkByteArrays(refData, baoutData);
baout.close();
in.close();
}
代码示例来源:origin: com.impetus.fabric/fabric-jdbc-driver-shaded
/**
* Fetches entire contents of an <code>InputStream</code> and represent
* same data as result InputStream.
* <p>
* This method is useful where,
* <ul>
* <li>Source InputStream is slow.</li>
* <li>It has network resources associated, so we cannot keep it open for
* long time.</li>
* <li>It has network timeout associated.</li>
* </ul>
* It can be used in favor of {@link #toByteArray()}, since it
* avoids unnecessary allocation and copy of byte[].<br>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input Stream to be fully buffered.
* @param size the initial buffer size
* @return A fully buffered stream.
* @throws IOException if an I/O error occurs
* @since 2.5
*/
public static InputStream toBufferedInputStream(final InputStream input, final int size)
throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
@SuppressWarnings("resource")
final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
output.write(input);
return output.toInputStream();
}
代码示例来源:origin: io.github.stephenc.docker/docker-client-shaded
/**
* Fetches entire contents of an <code>InputStream</code> and represent
* same data as result InputStream.
* <p>
* This method is useful where,
* <ul>
* <li>Source InputStream is slow.</li>
* <li>It has network resources associated, so we cannot keep it open for
* long time.</li>
* <li>It has network timeout associated.</li>
* </ul>
* It can be used in favor of {@link #toByteArray()}, since it
* avoids unnecessary allocation and copy of byte[].<br>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input Stream to be fully buffered.
* @param size the initial buffer size
* @return A fully buffered stream.
* @throws IOException if an I/O error occurs
* @since 2.5
*/
public static InputStream toBufferedInputStream(final InputStream input, int size)
throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
@SuppressWarnings("resource")
final ByteArrayOutputStream output = new ByteArrayOutputStream(size);
output.write(input);
return output.toInputStream();
}
代码示例来源:origin: Snapcept/Snapcept
InputStream fakeStream = bufferStream.toInputStream();
return bufferStream.toInputStream();
代码示例来源:origin: Snapcept/Snapcept
bufferStream.write(inputStream);
IOUtils.closeQuietly(inputStream);
inputStream = bufferStream.toInputStream();
SnapConstants.SNAP_VIDEO_DECRYPTOR_METHOD_DECRYPT,
param.args[0],
new BufferedInputStream(bufferStream.toInputStream()),
param.args[2],
param.args[3],
代码示例来源:origin: com.norconex.collectors/norconex-importer
streamFactory.newInputStream(os.toInputStream()),
pageMeta);
pageDocs.add(pageDoc);
内容来源于网络,如有侵权,请联系作者删除!