Search in sources :

Example 1 with FileStoreOutputStream

use of org.h2.store.FileStoreOutputStream in project h2database by h2database.

the class ScriptBase method openOutput.

/**
 * 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);
    }
}
Also used : FileStoreOutputStream(org.h2.store.FileStoreOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) FileStoreOutputStream(org.h2.store.FileStoreOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with FileStoreOutputStream

use of org.h2.store.FileStoreOutputStream in project h2database by h2database.

the class ValueLob method createFromReader.

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;
            }
        }
    }
}
Also used : FileStoreOutputStream(org.h2.store.FileStoreOutputStream)

Example 3 with FileStoreOutputStream

use of org.h2.store.FileStoreOutputStream in project h2database by h2database.

the class ValueLob method createFromStream.

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;
            }
        }
    }
}
Also used : FileStoreOutputStream(org.h2.store.FileStoreOutputStream)

Example 4 with FileStoreOutputStream

use of org.h2.store.FileStoreOutputStream in project h2database by h2database.

the class CreateScriptFile method openScriptWriter.

/**
 * Open a script writer.
 *
 * @param fileName the file name (the file will be overwritten)
 * @param compressionAlgorithm the compression algorithm (uppercase)
 * @param cipher the encryption algorithm or null
 * @param password the encryption password
 * @param charset the character set (for example UTF-8)
 * @return the print writer
 */
public static PrintWriter openScriptWriter(String fileName, String compressionAlgorithm, String cipher, String password, String charset) throws IOException {
    try {
        OutputStream out;
        if (cipher != null) {
            byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
            FileUtils.delete(fileName);
            FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
            store.init();
            out = new FileStoreOutputStream(store, null, compressionAlgorithm);
            out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE_COMPRESS);
        } else {
            out = FileUtils.newOutputStream(fileName, false);
            out = new BufferedOutputStream(out, Constants.IO_BUFFER_SIZE);
            out = CompressTool.wrapOutputStream(out, compressionAlgorithm, "script.sql");
        }
        return new PrintWriter(new OutputStreamWriter(out, charset));
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : FileStore(org.h2.store.FileStore) OutputStream(java.io.OutputStream) FileStoreOutputStream(org.h2.store.FileStoreOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) FileStoreOutputStream(org.h2.store.FileStoreOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Aggregations

FileStoreOutputStream (org.h2.store.FileStoreOutputStream)4 BufferedOutputStream (java.io.BufferedOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 FileStore (org.h2.store.FileStore)1