@Override protected void finalize() { close(); }
@Override public int read(byte[] buff) throws IOException { return read(buff, 0, buff.length); }
@Override public int read(byte[] b, int off, int len) throws IOException { if (len == 0) { return 0; } int read = 0; while (len > 0) { int r = readBlock(b, off, len); if (r < 0) { break; } read += r; off += r; len -= r; } return read == 0 ? -1 : read; }
@Override public InputStream getInputStream() { if (small != null) { return new ByteArrayInputStream(small); } else if (fileName != null) { FileStorage fileStorage = handler.openFile(fileName, "r", true); boolean alwaysClose = SysProperties.LOB_CLOSE_BETWEEN_READS; return new BufferedInputStream(new FileStorageInputStream(fileStorage, handler, false, alwaysClose), Constants.IO_BUFFER_SIZE); } long byteCount = (type == Value.BLOB) ? precision : -1; try { return handler.getLobStorage().getInputStream(this, hmac, byteCount); } catch (IOException e) { throw DbException.convertIOException(e, toString()); } }
public FileStorageInputStream(FileStorage fileStorage, DataHandler handler, boolean compression, boolean alwaysClose) { this.fileStorage = fileStorage; this.alwaysClose = alwaysClose; if (compression) { compress = CompressTool.getInstance(); } else { compress = null; } page = DataBuffer.create(handler, Constants.FILE_BLOCK_SIZE); try { if (fileStorage.length() <= FileStorage.HEADER_LENGTH) { close(); } else { fillBuffer(); } } catch (IOException e) { throw DbException.convertIOException(e, fileStorage.name); } }
private int readBlock(byte[] buff, int off, int len) throws IOException { fillBuffer(); if (endOfFile) { return -1; } int l = Math.min(remainingInBuffer, len); page.read(buff, off, l); remainingInBuffer -= l; return l; }
/** * Open the input stream. */ void openInput() { String file = getFileName(); if (file == null) { return; } if (isEncrypted()) { initStore(); in = new FileStorageInputStream(fileStorage, this, compressionAlgorithm != null, false); } else { InputStream inStream; try { inStream = FileUtils.newInputStream(file); } catch (IOException e) { throw DbException.convertIOException(e, file); } in = new BufferedInputStream(inStream, Constants.IO_BUFFER_SIZE); in = CompressTool.wrapInputStream(in, compressionAlgorithm, SCRIPT_SQL); if (in == null) { throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, SCRIPT_SQL + " in " + file); } } }
@Override public int read() throws IOException { fillBuffer(); if (endOfFile) { return -1; } int i = page.readByte() & 0xff; remainingInBuffer--; return i; }