本文整理了Java中org.apache.commons.io.IOUtils.copyLarge()
方法的一些代码示例,展示了IOUtils.copyLarge()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copyLarge()
方法的具体详情如下:
包路径:org.apache.commons.io.IOUtils
类名称:IOUtils
方法名:copyLarge
[英]Copy bytes from a large (over 2GB) InputStream
to an OutputStream
.
This method buffers the input internally, so there is no need to use a BufferedInputStream
.
The buffer size is given by #DEFAULT_BUFFER_SIZE.
[中]将字节从较大(超过2GB)InputStream
复制到OutputStream
。
此方法在内部缓冲输入,因此无需使用BufferedInputStream
。
缓冲区大小由#默认_buffer_size给出。
代码示例来源:origin: commons-io/commons-io
/**
* Copies chars from a large (over 2GB) <code>Reader</code> to a <code>Writer</code>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
* <p>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>Reader</code> to read from
* @param output the <code>Writer</code> to write to
* @return the number of characters copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since 1.3
*/
public static long copyLarge(final Reader input, final Writer output) throws IOException {
return copyLarge(input, output, new char[DEFAULT_BUFFER_SIZE]);
}
代码示例来源:origin: commons-io/commons-io
/**
* Copies bytes from an <code>InputStream</code> to an <code>OutputStream</code> using an internal buffer of the
* given size.
* <p>
* This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>.
* <p>
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
* @param bufferSize the bufferSize used to copy from the input to the output
* @return the number of bytes copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since 2.5
*/
public static long copy(final InputStream input, final OutputStream output, final int bufferSize)
throws IOException {
return copyLarge(input, output, new byte[bufferSize]);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @deprecated Use instead {@link org.apache.commons.io.IOUtils#copyLarge(java.io.InputStream, java.io.OutputStream)}
*/
@Deprecated
public static long copyLarge(InputStream input, OutputStream output) throws IOException {
return org.apache.commons.io.IOUtils.copyLarge(input, output);
}
代码示例来源:origin: jenkinsci/jenkins
/**
* @deprecated Use instead {@link org.apache.commons.io.IOUtils#copyLarge(java.io.Reader, java.io.Writer)}
*/
@Deprecated
public static long copyLarge(Reader input, Writer output) throws IOException {
return org.apache.commons.io.IOUtils.copyLarge(input, output);
}
代码示例来源:origin: commons-io/commons-io
/**
* Copies some or all chars from a large (over 2GB) <code>InputStream</code> to an
* <code>OutputStream</code>, optionally skipping input chars.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
* <p>
* The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
*
* @param input the <code>Reader</code> to read from
* @param output the <code>Writer</code> to write to
* @param inputOffset : number of chars to skip from input before copying
* -ve values are ignored
* @param length : number of chars to copy. -ve means all
* @return the number of chars copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since 2.2
*/
public static long copyLarge(final Reader input, final Writer output, final long inputOffset, final long length)
throws IOException {
return copyLarge(input, output, inputOffset, length, new char[DEFAULT_BUFFER_SIZE]);
}
代码示例来源:origin: commons-io/commons-io
/**
* Copy bytes from a <code>File</code> to an <code>OutputStream</code>.
* <p>
* This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>.
* </p>
*
* @param input the <code>File</code> to read from
* @param output the <code>OutputStream</code> to write to
* @return the number of bytes copied
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since 2.1
*/
public static long copyFile(final File input, final OutputStream output) throws IOException {
try (FileInputStream fis = new FileInputStream(input)) {
return IOUtils.copyLarge(fis, output);
}
}
代码示例来源:origin: gocd/gocd
public void streamToFile(InputStream stream, File dest) throws IOException {
dest.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(dest, true);
try {
IOUtils.copyLarge(stream, out);
} finally {
IOUtils.closeQuietly(out);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_CharSkipInvalid() throws IOException {
CharArrayReader is = null;
CharArrayWriter os = null;
try {
// Create streams
is = new CharArrayReader(carr);
os = new CharArrayWriter();
// Test our copy method
IOUtils.copyLarge(is, os, 1000, 100);
fail("Should have thrown EOFException");
} catch (final EOFException ignore) {
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_SkipInvalid() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
IOUtils.copyLarge(is, os, 1000, 100);
fail("Should have thrown EOFException");
} catch (final EOFException ignore) {
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopy_readerToWriter_IO84() throws Exception {
final long size = (long)Integer.MAX_VALUE + (long)1;
final Reader reader = new NullReader(size);
final Writer writer = new NullWriter();
// Test copy() method
assertEquals(-1, IOUtils.copy(reader, writer));
// reset the input
reader.close();
// Test copyLarge() method
assertEquals("copyLarge()", size, IOUtils.copyLarge(reader, writer));
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopy_inputStreamToOutputStream_IO84() throws Exception {
final long size = (long)Integer.MAX_VALUE + (long)1;
final InputStream in = new NullInputStream(size);
final OutputStream out = new NullOutputStream();
// Test copy() method
assertEquals(-1, IOUtils.copy(in, out));
// reset the input
in.close();
// Test copyLarge() method
assertEquals("copyLarge()", size, IOUtils.copyLarge(in, out));
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_CharFullLength() throws IOException {
CharArrayReader is = null;
CharArrayWriter os = null;
try {
// Create streams
is = new CharArrayReader(carr);
os = new CharArrayWriter();
// Test our copy method
assertEquals(200, IOUtils.copyLarge(is, os, 0, -1));
final char[] oarr = os.toCharArray();
// check that output length is correct
assertEquals(200, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals((char) -1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_CharSkip() throws IOException {
CharArrayReader is = null;
CharArrayWriter os = null;
try {
// Create streams
is = new CharArrayReader(carr);
os = new CharArrayWriter();
// Test our copy method
assertEquals(100, IOUtils.copyLarge(is, os, 10, 100));
final char[] oarr = os.toCharArray();
// check that output length is correct
assertEquals(100, oarr.length);
// check that output data corresponds to input data
assertEquals(11, oarr[1]);
assertEquals(79, oarr[69]);
assertEquals((char) -1, oarr[70]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_FullLength() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
assertEquals(200, IOUtils.copyLarge(is, os, 0, -1));
final byte[] oarr = os.toByteArray();
// check that output length is correct
assertEquals(200, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals(-1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_Skip() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
assertEquals(100, IOUtils.copyLarge(is, os, 10, 100));
final byte[] oarr = os.toByteArray();
// check that output length is correct
assertEquals(100, oarr.length);
// check that output data corresponds to input data
assertEquals(11, oarr[1]);
assertEquals(79, oarr[69]);
assertEquals(-1, oarr[70]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_ExtraLength() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
// for extra length, it reads till EOF
assertEquals(200, IOUtils.copyLarge(is, os, 0, 2000));
final byte[] oarr = os.toByteArray();
// check that output length is correct
assertEquals(200, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals(-1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test
public void testCopyLarge_SkipWithInvalidOffset() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
assertEquals(100, IOUtils.copyLarge(is, os, -10, 100));
final byte[] oarr = os.toByteArray();
// check that output length is correct
assertEquals(100, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals(-1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_CharNoSkip() throws IOException {
CharArrayReader is = null;
CharArrayWriter os = null;
try {
// Create streams
is = new CharArrayReader(carr);
os = new CharArrayWriter();
// Test our copy method
assertEquals(100, IOUtils.copyLarge(is, os, 0, 100));
final char[] oarr = os.toCharArray();
// check that output length is correct
assertEquals(100, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals((char) -1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_NoSkip() throws IOException {
ByteArrayInputStream is = null;
ByteArrayOutputStream os = null;
try {
// Create streams
is = new ByteArrayInputStream(iarr);
os = new ByteArrayOutputStream();
// Test our copy method
assertEquals(100, IOUtils.copyLarge(is, os, 0, 100));
final byte[] oarr = os.toByteArray();
// check that output length is correct
assertEquals(100, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals(-1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
代码示例来源:origin: commons-io/commons-io
@Test public void testCopyLarge_CharExtraLength() throws IOException {
CharArrayReader is = null;
CharArrayWriter os = null;
try {
// Create streams
is = new CharArrayReader(carr);
os = new CharArrayWriter();
// Test our copy method
// for extra length, it reads till EOF
assertEquals(200, IOUtils.copyLarge(is, os, 0, 2000));
final char[] oarr = os.toCharArray();
// check that output length is correct
assertEquals(200, oarr.length);
// check that output data corresponds to input data
assertEquals(1, oarr[1]);
assertEquals(79, oarr[79]);
assertEquals((char) -1, oarr[80]);
} finally {
IOUtils.closeQuietly(is);
IOUtils.closeQuietly(os);
}
}
内容来源于网络,如有侵权,请联系作者删除!