/** * Copy all data from the input stream to the output stream. Both streams * are kept open. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, Long.MAX_VALUE); }
@Override public void call() throws IOException { IOUtils.copy(in, out); } }.execute();
/** * Read a number of bytes from an input stream and close the stream. * * @param in the input stream * @param length the maximum number of bytes to read, or -1 to read until * the end of file * @return the bytes read */ public static byte[] readBytesAndClose(InputStream in, int length) throws IOException { try { if (length <= 0) { length = Integer.MAX_VALUE; } int block = Math.min(Constants.IO_BUFFER_SIZE, length); ByteArrayOutputStream out = new ByteArrayOutputStream(block); copy(in, out, length); return out.toByteArray(); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { in.close(); } }
IOUtils.copy(zipIn, out); zipIn.closeEntry(); return out.toByteArray();
/** * Copy all data from the input stream to the output stream and close the * input stream. Exceptions while closing are ignored. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException { try { return copy(in, out); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { closeSilently(in); } }
o = FileUtils.newOutputStream( directory + SysProperties.FILE_SEPARATOR + fileName, false); IOUtils.copy(zipIn, o); o.close(); } finally {
/** * Returns some bytes of the object. * * @param pos the index, the first byte is at position 1 * @param length the number of bytes * @return the bytes, at most length bytes */ @Override public byte[] getBytes(long pos, int length) throws SQLException { try { if (isDebugEnabled()) { debugCode("getBytes("+pos+", "+length+");"); } checkClosed(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (InputStream in = value.getInputStream()) { IOUtils.skipFully(in, pos - 1); IOUtils.copy(in, out, length); } return out.toByteArray(); } catch (Exception e) { throw logAndConvert(e); } }
private void dumpLob(String fileName, boolean lobCompression) { OutputStream fileOut = null; FileStore fileStore = null; long size = 0; String n = fileName + (lobCompression ? ".comp" : "") + ".txt"; InputStream in = null; try { fileOut = FileUtils.newOutputStream(n, false); fileStore = FileStore.open(null, fileName, "r"); fileStore.init(); in = new FileStoreInputStream(fileStore, this, lobCompression, false); size = IOUtils.copy(in, fileOut); } catch (Throwable e) { // this is usually not a problem, because we try both compressed and // uncompressed } finally { IOUtils.closeSilently(fileOut); IOUtils.closeSilently(in); closeSilently(fileStore); } if (size == 0) { try { FileUtils.delete(n); } catch (Exception e) { traceError(n, e); } } }
/** * Copy all data from the input stream to the output stream. Both streams * are kept open. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, Long.MAX_VALUE); }
/** * Copy all data from the input stream to the output stream. Both streams * are kept open. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copy(InputStream in, OutputStream out) throws IOException { return copy(in, out, Long.MAX_VALUE); }
@Override public void call() throws IOException { IOUtils.copy(in, out); } }.execute();
@Override public void call() throws IOException { IOUtils.copy(in, out); } }.execute();
public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException { try { return copy(in, out); } finally { closeSilently(in); } }
public synchronized void receive(FileSystem fs, String fileName) throws IOException, SQLException { connect(); try { InputStream in = socket.getInputStream(); OutputStream out = fs.openFileOutputStream(fileName, false); IOUtils.copy(in, out); out.close(); } finally { socket.close(); } server.trace("closed"); }
/** * Read a number of bytes from an input stream and close the stream. * * @param in the input stream * @param length the maximum number of bytes to read, or -1 to read until * the end of file * @return the bytes read */ public static byte[] readBytesAndClose(InputStream in, int length) throws IOException { try { if (length <= 0) { length = Integer.MAX_VALUE; } int block = Math.min(Constants.IO_BUFFER_SIZE, length); ByteArrayOutputStream out = new ByteArrayOutputStream(block); copy(in, out, length); return out.toByteArray(); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { in.close(); } }
/** * Read a number of bytes from an input stream and close the stream. * * @param in the input stream * @param length the maximum number of bytes to read, or -1 to read until * the end of file * @return the bytes read */ public static byte[] readBytesAndClose(InputStream in, int length) throws IOException { try { if (length <= 0) { length = Integer.MAX_VALUE; } int block = Math.min(Constants.IO_BUFFER_SIZE, length); ByteArrayOutputStream out = new ByteArrayOutputStream(block); copy(in, out, length); return out.toByteArray(); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { in.close(); } }
public synchronized void send(FileSystem fs, String fileName, long skip) throws IOException { connect(); try { OutputStream out = socket.getOutputStream(); InputStream in = fs.openFileInputStream(fileName); IOUtils.skipFully(in, skip); IOUtils.copy(in, out); in.close(); } finally { socket.close(); } server.trace("closed"); }
/** * Copy all data from the input stream to the output stream and close the * input stream. Exceptions while closing are ignored. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException { try { return copy(in, out); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { closeSilently(in); } }
/** * Copy all data from the input stream to the output stream and close the * input stream. Exceptions while closing are ignored. * * @param in the input stream * @param out the output stream (null if writing is not required) * @return the number of bytes copied */ public static long copyAndCloseInput(InputStream in, OutputStream out) throws IOException { try { return copy(in, out); } catch (Exception e) { throw DbException.convertToIOException(e); } finally { closeSilently(in); } }
/** * Returns some bytes of the object. * * @param pos the index, the first byte is at position 1 * @param length the number of bytes * @return the bytes, at most length bytes */ @Override public byte[] getBytes(long pos, int length) throws SQLException { try { if (isDebugEnabled()) { debugCode("getBytes("+pos+", "+length+");"); } checkClosed(); ByteArrayOutputStream out = new ByteArrayOutputStream(); try (InputStream in = value.getInputStream()) { IOUtils.skipFully(in, pos - 1); IOUtils.copy(in, out, length); } return out.toByteArray(); } catch (Exception e) { throw logAndConvert(e); } }