private static void backupFile(ZipOutputStream out, InputStream in, String entryName) throws IOException { out.putNextEntry(new ZipEntry(entryName)); IOUtils.copyAndCloseInput(in, out); out.closeEntry(); } }
/** * Read a number of characters from a reader and close it. * * @param in the reader * @param length the maximum number of characters to read, or -1 to read * until the end of file * @return the string read */ public static String readStringAndClose(Reader in, int length) throws IOException { try { if (length <= 0) { length = Integer.MAX_VALUE; } int block = Math.min(Constants.IO_BUFFER_SIZE, length); StringWriter out = new StringWriter(block); copyAndCloseInput(in, out, length); return out.toString(); } finally { in.close(); } }
/** * Copy all data from the input stream to the output stream and close both * streams. Exceptions while closing are ignored. * * @param in the input stream * @param out the output stream * @return the number of bytes copied */ public static long copyAndClose(InputStream in, OutputStream out) throws IOException { try { long len = copyAndCloseInput(in, out); out.close(); return len; } catch (Exception e) { throw DbException.convertToIOException(e); } finally { closeSilently(out); } }
try { IOUtils.skipFully(reader, pos - 1); IOUtils.copyAndCloseInput(reader, writer, length); } finally { reader.close();
/** * Returns the length. * * @return the length */ @Override public long length() throws SQLException { try { debugCodeCall("length"); checkClosed(); if (value.getType() == Value.CLOB) { long precision = value.getPrecision(); if (precision > 0) { return precision; } } return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE); } catch (Exception e) { throw logAndConvert(e); } }
/** * Returns the length. * * @return the length * @throws SQLException */ @Override public long length() throws SQLException { try { debugCodeCall("length"); checkClosed(); if (value.getType() == Value.BLOB) { long precision = value.getPrecision(); if (precision > 0) { return precision; } } return IOUtils.copyAndCloseInput(value.getInputStream(), null); } catch (Exception e) { throw logAndConvert(e); } }
long written = IOUtils.copyAndCloseInput(v.getInputStream(), out); if (written != length) { throw DbException.get(ErrorCode.CONNECTION_BROKEN_1, "length:" + length + " written:" + written);