data = ((Clob) data).getCharacterStream(); return IOUtils.readStringAndClose((Reader) data, -1); } catch (IOException e) { throw DbException.toSQLException(e);
/** * 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 a file from one directory to another, or to another file. * * @param original the original file name * @param copy the file name of the copy */ public static void copyFiles(String original, String copy) throws IOException { InputStream in = FileUtils.newInputStream(original); OutputStream out = FileUtils.newOutputStream(copy, false); copyAndClose(in, out); }
/** * 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); } }
return null; return IOUtils.readBytesAndClose(in, 0); IOUtils.copy(zipIn, out); zipIn.closeEntry(); return out.toByteArray();
@Override public String getString() { int len = precision > Integer.MAX_VALUE || precision == 0 ? Integer.MAX_VALUE : (int) precision; try { if (type == Value.CLOB) { if (small != null) { return new String(small, StandardCharsets.UTF_8); } return IOUtils.readStringAndClose(getReader(), len); } byte[] buff; if (small != null) { buff = small; } else { buff = IOUtils.readBytesAndClose(getInputStream(), len); } return StringUtils.convertBytesToHex(buff); } catch (IOException e) { throw DbException.convertIOException(e, fileName); } }
try { if (handler == null) { String s = IOUtils.readStringAndClose(in, (int) length); return createSmallLob(Value.CLOB, s.getBytes(StandardCharsets.UTF_8)); char[] buff; if (len >= Integer.MAX_VALUE) { String data = IOUtils.readStringAndClose(in, -1); buff = data.toCharArray(); len = buff.length; } else { buff = new char[len]; len = IOUtils.readFully(in, buff, len);
/** * INTERNAL */ @Override public void close() { IOUtils.closeSilently(input); input = null; IOUtils.closeSilently(output); output = null; }
/** * Updates a column in the current or insert row. * * @param columnIndex (1,2,...) * @param x the value * @param length the number of characters * @throws SQLException if the result set is closed or not updatable */ @Override public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { try { if (isDebugEnabled()) { debugCode("updateAsciiStream("+columnIndex+", x, "+length+"L);"); } checkClosed(); Value v = conn.createClob(IOUtils.getAsciiReader(x), length); update(columnIndex, v); } catch (Exception e) { throw logAndConvert(e); } }
private String readSqlFrom(Resource resource) throws IOException { return readStringAndClose(getBufferedReader(resource.getInputStream()), -1); }
String script) throws IOException { LineNumberReader reader = new LineNumberReader( IOUtils.getBufferedReader( FileUtils.newInputStream(traceFileName))); PrintWriter javaWriter = new PrintWriter( IOUtils.getBufferedWriter( FileUtils.newOutputStream(javaClassName + ".java", false))); PrintWriter scriptWriter = new PrintWriter( IOUtils.getBufferedWriter( FileUtils.newOutputStream(script, false))); javaWriter.println("import java.io.*;");
/** * Read a number of bytes. * * @param buff the target buffer * @param len the number of bytes to read */ public void readFully(byte[] buff, int len) throws IOException { int got = IOUtils.readFully(in, buff, len); if (got < len) { throw new FastEOFException(); } }
try { if (handler == null) { byte[] data = IOUtils.readBytesAndClose(in, (int) length); return createSmallLob(Value.BLOB, data); byte[] buff; if (len >= Integer.MAX_VALUE) { buff = IOUtils.readBytesAndClose(in, -1); len = buff.length; } else { buff = Utils.newBytes(len); len = IOUtils.readFully(in, buff, len);
@Override public void call() throws IOException { IOUtils.copy(in, out); } }.execute();
/** * 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(); } }
/** * 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); } }
IOUtils.closeSilently(in); FileOutputStream fileOutputStream = new FileOutputStream(fileName); try (InputStream in = v0.getInputStream()) { result = ValueLong.get(IOUtils.copyAndClose(in, fileOutputStream));
Math.min(Constants.IO_BUFFER_SIZE, length)); try (Reader reader = value.getReader()) { IOUtils.skipFully(reader, pos - 1); IOUtils.copyAndCloseInput(reader, writer, length);
@Override public void call() { value = c.createClob(IOUtils.getReader(in), -1); } };
@Override public Reader getReader() { return IOUtils.getBufferedReader(getInputStream()); }