本文整理了Java中org.apache.tika.io.IOUtils.copy()
方法的一些代码示例,展示了IOUtils.copy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copy()
方法的具体详情如下:
包路径:org.apache.tika.io.IOUtils
类名称:IOUtils
方法名:copy
[英]Copy bytes from an InputStream
to an OutputStream
.
This method buffers the input internally, so there is no need to use a BufferedInputStream
.
Large streams (over 2GB) will return a bytes copied value of -1
after the copy has completed since the correct number of bytes cannot be returned as an int. For large streams use the copyLarge(InputStream, OutputStream)
method.
[中]将字节从InputStream
复制到OutputStream
。
此方法在内部缓冲输入,因此无需使用BufferedInputStream
。
复制完成后,大数据流(超过2GB)将返回字节复制值-1
,因为无法将正确的字节数作为整数返回。对于大数据流,请使用copyLarge(InputStream, OutputStream)
方法。
代码示例来源:origin: apache/tika
public void run() {
try {
try {
IOUtils.copy(input, output);
} finally {
output.close();
}
} catch (Exception e) {
exception = e;
}
}
代码示例来源:origin: apache/tika
public void run() {
OutputStream stdin = process.getOutputStream();
try {
IOUtils.copy(stream, stdin);
} catch (IOException e) {
}
}
};
代码示例来源:origin: apache/tika
public void run() {
try {
IOUtils.copy(inputStream, outputStream);
} catch (IOException e) {
System.out.println("ERROR: " + e.getMessage());
}
}
}).start();
代码示例来源:origin: apache/tika
/**
* Copy bytes from an <code>InputStream</code> to chars on a
* <code>Writer</code> using the specified character encoding.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method uses {@link InputStreamReader}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>Writer</code> to write to
* @param encoding the encoding to use, null means platform default
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static void copy(InputStream input, Writer output, String encoding)
throws IOException {
if (encoding == null) {
copy(input, output);
} else {
InputStreamReader in = new InputStreamReader(input, encoding);
copy(in, output);
}
}
代码示例来源:origin: apache/tika
/**
* Copy bytes from an <code>InputStream</code> to chars on a
* <code>Writer</code> using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
* <p>
* This method uses {@link InputStreamReader}.
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>Writer</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static void copy(InputStream input, Writer output)
throws IOException {
InputStreamReader in = new InputStreamReader(input, UTF_8);
copy(in, output);
}
代码示例来源:origin: apache/tika
/**
* Get the contents of a <code>Reader</code> as a character array.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
*
* @param input the <code>Reader</code> to read from
* @return the requested character array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static char[] toCharArray(Reader input) throws IOException {
CharArrayWriter sw = new CharArrayWriter();
copy(input, sw);
return sw.toCharArray();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a <code>byte[]</code>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @return the requested byte array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(InputStream input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of a <code>Reader</code> as a String.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
*
* @param input the <code>Reader</code> to read from
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toString(Reader input) throws IOException {
StringWriter sw = new StringWriter();
copy(input, sw);
return sw.toString();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of a <code>Reader</code> as a <code>byte[]</code>
* using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
*
* @param input the <code>Reader</code> to read from
* @return the requested byte array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static byte[] toByteArray(Reader input) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output);
return output.toByteArray();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a String
* using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toString(InputStream input) throws IOException {
StringWriter sw = new StringWriter();
copy(input, sw);
return sw.toString();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a character array
* using the default character encoding of the platform.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param is the <code>InputStream</code> to read from
* @return the requested character array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static char[] toCharArray(InputStream is) throws IOException {
CharArrayWriter output = new CharArrayWriter();
copy(is, output);
return output.toCharArray();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a String
* using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toString(InputStream input, String encoding)
throws IOException {
StringWriter sw = new StringWriter();
copy(input, sw, encoding);
return sw.toString();
}
代码示例来源:origin: apache/tika
/**
* Sends the standard output of the given
* process to the given output stream. Potential exceptions are
* ignored.
* <p>
* Note that the given output stream is <em>not</em> closed by this method.
*
* @param process the process
* @param outputStream the putput stream to send to standard input of the process
*/
private void sendStdOutToOutputStream(
final Process process,
final OutputStream outputStream) {
try {
IOUtils.copy(process.getInputStream(), outputStream);
} catch (IOException e) {
System.out.println("ERROR: " + e.getMessage());
}
}
代码示例来源:origin: apache/tika
/**
* Get the contents of an <code>InputStream</code> as a character array
* using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param is the <code>InputStream</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested character array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static char[] toCharArray(InputStream is, String encoding)
throws IOException {
CharArrayWriter output = new CharArrayWriter();
copy(is, output, encoding);
return output.toCharArray();
}
代码示例来源:origin: apache/tika
/**
* Get the contents of a <code>Reader</code> as a <code>byte[]</code>
* using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
*
* @param input the <code>Reader</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested byte array
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static byte[] toByteArray(Reader input, String encoding)
throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
copy(input, output, encoding);
return output.toByteArray();
}
代码示例来源:origin: apache/tika
/**
* Copy chars from a <code>Reader</code> to bytes on an
* <code>OutputStream</code> using the default character encoding of the
* platform, and calling flush.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedReader</code>.
* <p>
* Due to the implementation of OutputStreamWriter, this method performs a
* flush.
* <p>
* This method uses {@link OutputStreamWriter}.
*
* @param input the <code>Reader</code> to read from
* @param output the <code>OutputStream</code> to write to
* @throws NullPointerException if the input or output is null
* @throws IOException if an I/O error occurs
* @since Commons IO 1.1
*/
public static void copy(Reader input, OutputStream output)
throws IOException {
OutputStreamWriter out = new OutputStreamWriter(output, UTF_8);
copy(input, out);
// XXX Unless anyone is planning on rewriting OutputStreamWriter, we
// have to flush here.
out.flush();
}
代码示例来源:origin: apache/tika
public void run() {
try {
IOUtils.copy(stream, new NullOutputStream());
} catch (IOException e) {
} finally {
IOUtils.closeQuietly(stream);
}
}
};
代码示例来源:origin: apache/tika
private void writeTo(String language, Writer writer) throws IOException {
try (InputStream stream =
LanguageIdentifierTest.class.getResourceAsStream(
language + ".test")) {
IOUtils.copy(new InputStreamReader(stream, UTF_8), writer);
}
}
代码示例来源:origin: apache/tika
@Override
public void handle(String filename, MediaType mediaType,
InputStream stream) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
if (! stream.markSupported()) {
stream = TikaInputStream.get(stream);
}
stream.mark(0);
try {
IOUtils.copy(stream, os);
bytes.add(os.toByteArray());
stream.reset();
} catch (IOException e) {
//swallow
}
}
}
代码示例来源:origin: apache/tika
IOUtils.copy(zipArchiveInputStream, outputStream);
successfullyCopied = true;
} catch (IOException e) {
内容来源于网络,如有侵权,请联系作者删除!