/** * Create a CLOB in a temporary file. */ private ValueLobDb(DataHandler handler, Reader in, long remaining) throws IOException { this.type = Value.CLOB; this.handler = handler; this.small = null; this.lobId = 0; this.hmac = null; this.fileName = createTempLobFileName(handler); this.tempFile = this.handler.openFile(fileName, "rw", false); this.tempFile.autoDelete(); long tmpPrecision = 0; try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null)) { char[] buff = new char[Constants.IO_BUFFER_SIZE]; while (true) { int len = getBufferSize(this.handler, false, remaining); len = IOUtils.readFully(in, buff, len); if (len == 0) { break; } byte[] data = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8); out.write(data); tmpPrecision += len; } } this.precision = tmpPrecision; this.tableId = 0; }
this.tempFile = this.handler.openFile(fileName, "rw", false); this.tempFile.autoDelete(); FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null); long tmpPrecision = 0; try { out.write(data); tmpPrecision += len; out.close();
private void createFromReader(char[] buff, int len, Reader in, long remaining, DataHandler h) throws IOException { FileStoreOutputStream out = initLarge(h); boolean compress = h.getLobCompressionAlgorithm(Value.CLOB) != null; try { while (true) { precision += len; byte[] b = new String(buff, 0, len).getBytes(Constants.UTF8); out.write(b, 0, b.length); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(h, compress, remaining); len = IOUtils.readFully(in, buff, len); if (len == 0) { break; } } } finally { out.close(); } }
@Override public void write(int b) { buffer[0] = (byte) b; write(buffer); }
private FileStoreOutputStream initLarge(DataHandler h) { this.handler = h; this.tableId = 0; this.linked = false; this.precision = 0; this.small = null; this.hash = 0; String compressionAlgorithm = h.getLobCompressionAlgorithm(type); this.compressed = compressionAlgorithm != null; synchronized (h) { String path = h.getDatabasePath(); if ((path != null) && (path.length() == 0)) { path = new File(Utils.getProperty("java.io.tmpdir", "."), SysProperties.PREFIX_TEMP_FILE).getAbsolutePath(); } objectId = getNewObjectId(h); fileName = getFileNamePrefix(path, objectId) + Constants.SUFFIX_TEMP_FILE; tempFile = h.openFile(fileName, "rw", false); tempFile.autoDelete(); } return new FileStoreOutputStream(tempFile, h, compressionAlgorithm); }
this.tempFile = this.handler.openFile(fileName, "rw", false); this.tempFile.autoDelete(); FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null); long tmpPrecision = 0; boolean compress = this.handler.getLobCompressionAlgorithm(Value.BLOB) != null; while (true) { tmpPrecision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) { out.close();
private void createFromStream(byte[] buff, int len, InputStream in, long remaining, DataHandler h) throws IOException { FileStoreOutputStream out = initLarge(h); boolean compress = h.getLobCompressionAlgorithm(Value.BLOB) != null; try { while (true) { precision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(h, compress, remaining); len = IOUtils.readFully(in, buff, len); if (len <= 0) { break; } } } finally { out.close(); } }
@Override public void write(byte[] buff) { write(buff, 0, buff.length); }
/** * Open the output stream. */ void openOutput() { String file = getFileName(); if (file == null) { return; } if (isEncrypted()) { initStore(); out = new FileStoreOutputStream(store, this, compressionAlgorithm); // always use a big buffer, otherwise end-of-block is written a lot out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS); } else { OutputStream o; try { o = FileUtils.newOutputStream(file, false); } catch (IOException e) { throw DbException.convertIOException(e, null); } out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE); out = CompressTool.wrapOutputStream(out, compressionAlgorithm, SCRIPT_SQL); } }
this.tempFile = this.handler.openFile(fileName, "rw", false); this.tempFile.autoDelete(); FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null); long tmpPrecision = 0; boolean compress = this.handler.getLobCompressionAlgorithm(Value.BLOB) != null; while (true) { tmpPrecision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) { out.close();
private void createFromStream(byte[] buff, int len, InputStream in, long remaining, DataHandler handler) throws SQLException { try { FileStoreOutputStream out = initLarge(handler); boolean compress = handler.getLobCompressionAlgorithm(Value.BLOB) != null; try { while (true) { precision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(handler, compress, remaining); len = IOUtils.readFully(in, buff, 0, len); if (len <= 0) { break; } } } finally { out.close(); } } catch (IOException e) { throw Message.convertIOException(e, null); } }
long tmpPrecision = 0; boolean compress = this.handler.getLobCompressionAlgorithm(Value.BLOB) != null; try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null)) { while (true) { tmpPrecision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) {
private void createFromReader(char[] buff, int len, Reader in, long remaining, DataHandler h) throws IOException { try (FileStoreOutputStream out = initLarge(h)) { boolean compress = h.getLobCompressionAlgorithm(Value.CLOB) != null; while (true) { precision += len; byte[] b = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8); out.write(b, 0, b.length); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(h, compress, remaining); len = IOUtils.readFully(in, buff, len); if (len == 0) { break; } } } }
protected void openOutput() throws SQLException { String fileName = getFileName(); if (fileName == null) { return; } if (isEncrypted()) { initStore(); out = new FileStoreOutputStream(store, this, compressionAlgorithm); // always use a big buffer, otherwise end-of-block is written a lot out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS); } else { OutputStream o = FileUtils.openFileOutputStream(fileName, false); out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE); out = CompressTool.wrapOutputStream(out, compressionAlgorithm, Constants.SCRIPT_SQL); } }
private void createFromReader(char[] buff, int len, Reader in, long remaining, DataHandler handler) throws SQLException { try { FileStoreOutputStream out = initLarge(handler); boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null; try { while (true) { precision += len; byte[] b = StringUtils.utf8Encode(new String(buff, 0, len)); out.write(b, 0, b.length); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(handler, compress, remaining); len = IOUtils.readFully(in, buff, len); if (len <= 0) { break; } } } finally { out.close(); } } catch (IOException e) { throw Message.convertIOException(e, null); } }
/** * Create a CLOB in a temporary file. */ private ValueLobDb(DataHandler handler, Reader in, long remaining) throws IOException { this.type = Value.CLOB; this.handler = handler; this.small = null; this.lobId = 0; this.hmac = null; this.fileName = createTempLobFileName(handler); this.tempFile = this.handler.openFile(fileName, "rw", false); this.tempFile.autoDelete(); long tmpPrecision = 0; try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null, null)) { char[] buff = new char[Constants.IO_BUFFER_SIZE]; while (true) { int len = getBufferSize(this.handler, false, remaining); len = IOUtils.readFully(in, buff, len); if (len == 0) { break; } byte[] data = new String(buff, 0, len).getBytes("UTF-8"); out.write(data); tmpPrecision += len; } } this.precision = tmpPrecision; }
private void createFromStream(byte[] buff, int len, InputStream in, long remaining, DataHandler h) throws IOException { try (FileStoreOutputStream out = initLarge(h)) { boolean compress = h.getLobCompressionAlgorithm(Value.BLOB) != null; while (true) { precision += len; out.write(buff, 0, len); remaining -= len; if (remaining <= 0) { break; } len = getBufferSize(h, compress, remaining); len = IOUtils.readFully(in, buff, len); if (len <= 0) { break; } } } }
private FileStoreOutputStream initLarge(DataHandler h) { this.handler = h; this.tableId = 0; this.linked = false; this.precision = 0; this.small = null; this.hash = 0; String compressionAlgorithm = h.getLobCompressionAlgorithm(type); this.compressed = compressionAlgorithm != null; synchronized (h) { String path = h.getDatabasePath(); if ((path != null) && (path.length() == 0)) { path = new File(Utils.getProperty("java.io.tmpdir", "."), SysProperties.PREFIX_TEMP_FILE).getAbsolutePath(); } objectId = getNewObjectId(h); fileName = getFileNamePrefix(path, objectId) + Constants.SUFFIX_TEMP_FILE; tempFile = h.openFile(fileName, "rw", false); tempFile.autoDelete(); } FileStoreOutputStream out = new FileStoreOutputStream(tempFile, h, compressionAlgorithm); return out; }
@Override public void write(int b) { buffer[0] = (byte) b; write(buffer); }
/** * Open the output stream. */ void openOutput() { String file = getFileName(); if (file == null) { return; } if (isEncrypted()) { initStore(); out = new FileStoreOutputStream(store, this, compressionAlgorithm); // always use a big buffer, otherwise end-of-block is written a lot out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS); } else { OutputStream o; try { o = FileUtils.newOutputStream(file, false); } catch (IOException e) { throw DbException.convertIOException(e, null); } out = new BufferedOutputStream(o, Constants.IO_BUFFER_SIZE); out = CompressTool.wrapOutputStream(out, compressionAlgorithm, SCRIPT_SQL); } }