@Override public void close() throws IOException { if (closed) { return; } closed = true; try { rs.close(); } catch (SQLException e) { throw DbException.convertToIOException(e); } } };
@Override public void close() throws IOException { if (closed) { return; } closed = true; try { rs.close(); } catch (SQLException e) { throw DbException.convertToIOException(e); } } @Override
private static byte[] getKeyStoreBytes(KeyStore store, String password) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { store.store(bout, password.toCharArray()); } catch (Exception e) { throw DbException.convertToIOException(e); } return bout.toByteArray(); }
/** * Skip a number of characters in a reader. * * @param reader the reader * @param skip the number of characters to skip * @throws EOFException if the end of file has been reached before all * characters could be skipped * @throws IOException if an IO exception occurred while skipping */ public static void skipFully(Reader reader, long skip) throws IOException { try { while (skip > 0) { long skipped = reader.skip(skip); if (skipped <= 0) { throw new EOFException(); } skip -= skipped; } } catch (Exception e) { throw DbException.convertToIOException(e); } }
/** * Skip a number of bytes in an input stream. * * @param in the input stream * @param skip the number of bytes to skip * @throws EOFException if the end of file has been reached before all bytes * could be skipped * @throws IOException if an IO exception occurred while skipping */ public static void skipFully(InputStream in, long skip) throws IOException { try { while (skip > 0) { long skipped = in.skip(skip); if (skipped <= 0) { throw new EOFException(); } skip -= skipped; } } catch (Exception e) { throw DbException.convertToIOException(e); } }
@Override public void close() throws IOException { super.close(); try { task.get(); } catch (Exception e) { throw DbException.convertToIOException(e); } } };
@Override public void close() throws IOException { super.close(); try { task.get(); } catch (Exception e) { throw DbException.convertToIOException(e); } } };
/** * Try to read the given number of bytes to the buffer. This method reads * until the maximum number of bytes have been read or until the end of * file. * * @param in the input stream * @param buffer the output buffer * @param max the number of bytes to read at most * @return the number of bytes read, 0 meaning EOF */ public static int readFully(InputStream in, byte[] buffer, int max) throws IOException { try { int result = 0, len = Math.min(max, buffer.length); while (len > 0) { int l = in.read(buffer, result, len); if (l < 0) { break; } result += l; len -= l; } return result; } catch (Exception e) { throw DbException.convertToIOException(e); } }
/** * Try to read the given number of characters to the buffer. This method * reads until the maximum number of characters have been read or until the * end of file. * * @param in the reader * @param buffer the output buffer * @param max the number of characters to read at most * @return the number of characters read, 0 meaning EOF */ public static int readFully(Reader in, char[] buffer, int max) throws IOException { try { int result = 0, len = Math.min(max, buffer.length); while (len > 0) { int l = in.read(buffer, result, len); if (l < 0) { break; } result += l; len -= l; } return result; } catch (Exception e) { throw DbException.convertToIOException(e); } }
private void initWrite() throws IOException { if (output == null) { try { OutputStream out = FileUtils.newOutputStream(fileName, false); out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE); output = new BufferedWriter(new OutputStreamWriter(out, characterSet)); } catch (Exception e) { close(); throw DbException.convertToIOException(e); } } }
private void fillBuffer() throws IOException { if (buffer != null && bufferPos < buffer.length) { return; } if (remainingBytes <= 0) { return; } if (lobMapIndex >= lobMapBlocks.length) { System.out.println("halt!"); } try { buffer = readBlock(lobMapBlocks[lobMapIndex]); lobMapIndex++; bufferPos = 0; } catch (SQLException e) { throw DbException.convertToIOException(e); } }
@Override public int read(byte[] buff, int off, int length) throws IOException { if (length == 0) { return 0; } length = (int) Math.min(length, remainingBytes); if (length == 0) { return -1; } try { length = handler.readLob(lob, hmac, pos, buff, off, length); } catch (DbException e) { throw DbException.convertToIOException(e); } if (length == 0) { return -1; } remainingBytes -= length; pos += length; return length; }
/** * 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(); } }
@Override public int read() throws IOException { while (true) { try { if (current == null) { if (closed) { return -1; } if (!rs.next()) { close(); return -1; } current = rs.getBinaryStream(1); current = new BufferedInputStream(current); } int x = current.read(); if (x >= 0) { return x; } current = null; } catch (SQLException e) { throw DbException.convertToIOException(e); } } } @Override
@Override public int read() throws IOException { while (true) { try { if (current == null) { if (closed) { return -1; } if (!rs.next()) { close(); return -1; } current = rs.getCharacterStream(1); current = new BufferedReader(current); } int x = current.read(); if (x >= 0) { return x; } current = null; } catch (SQLException e) { throw DbException.convertToIOException(e); } } } @Override
/** * 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); } }
/** * 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); } }
@Override public InputStream getInputStream(ValueLobDb lob, byte[] hmac, long byteCount) throws IOException { try { init(); assertNotHolds(conn.getSession()); // see locking discussion at the top synchronized (database) { synchronized (conn.getSession()) { long lobId = lob.getLobId(); return new LobInputStream(lobId, byteCount); } } } catch (SQLException e) { throw DbException.convertToIOException(e); } }
private ValueLobDb createLob(InputStream in, int type) throws IOException { byte[] streamStoreId; try { streamStoreId = streamStore.put(in); } catch (Exception e) { throw DbException.convertToIOException(e); } long lobId = generateLobId(); long length = streamStore.length(streamStoreId); int tableId = LobStorageFrontend.TABLE_TEMP; Object[] value = { streamStoreId, tableId, length, 0 }; lobMap.put(lobId, value); Object[] key = { streamStoreId, lobId }; refMap.put(key, Boolean.TRUE); ValueLobDb lob = ValueLobDb.create( type, database, tableId, lobId, null, length); if (TRACE) { trace("create " + tableId + "/" + lobId); } return lob; }
private void fillBuffer() throws IOException { if (buffer != null && pos < bufferLength) { return; } int len = readInt(); if (decompress == null) { // EOF this.bufferLength = 0; } else if (len < 0) { len = -len; buffer = ensureSize(buffer, len); readFully(buffer, len); this.bufferLength = len; } else { inBuffer = ensureSize(inBuffer, len); int size = readInt(); readFully(inBuffer, len); buffer = ensureSize(buffer, size); try { decompress.expand(inBuffer, 0, len, buffer, 0, size); } catch (ArrayIndexOutOfBoundsException e) { DbException.convertToIOException(e); } this.bufferLength = size; } pos = 0; }