Search in sources :

Example 1 with FileStoreInputStream

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

the class ScriptBase method openInput.

/**
 * Open the input stream.
 */
void openInput() {
    String file = getFileName();
    if (file == null) {
        return;
    }
    if (isEncrypted()) {
        initStore();
        in = new FileStoreInputStream(store, 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);
        }
    }
}
Also used : FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 2 with FileStoreInputStream

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

the class CreateScriptFile method openScriptReader.

/**
 * Open a script reader.
 *
 * @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 script reader
 */
public static LineNumberReader openScriptReader(String fileName, String compressionAlgorithm, String cipher, String password, String charset) throws IOException {
    try {
        InputStream in;
        if (cipher != null) {
            byte[] key = SHA256.getKeyPasswordHash("script", password.toCharArray());
            FileStore store = FileStore.open(null, fileName, "rw", cipher, key);
            store.init();
            in = new FileStoreInputStream(store, null, compressionAlgorithm != null, false);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE_COMPRESS);
        } else {
            in = FileUtils.newInputStream(fileName);
            in = new BufferedInputStream(in, Constants.IO_BUFFER_SIZE);
            in = CompressTool.wrapInputStream(in, compressionAlgorithm, "script.sql");
            if (in == null) {
                throw new IOException("Entry not found: script.sql in " + fileName);
            }
        }
        return new LineNumberReader(new InputStreamReader(in, charset));
    } catch (Exception e) {
        throw new IOException(e.getMessage(), e);
    }
}
Also used : FileStore(org.h2.store.FileStore) InputStreamReader(java.io.InputStreamReader) FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 3 with FileStoreInputStream

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

the class ValueLob method getInputStream.

@Override
public InputStream getInputStream() {
    if (fileName == null) {
        return new ByteArrayInputStream(small);
    }
    FileStore store = handler.openFile(fileName, "r", true);
    boolean alwaysClose = SysProperties.lobCloseBetweenReads;
    return new BufferedInputStream(new FileStoreInputStream(store, handler, compressed, alwaysClose), Constants.IO_BUFFER_SIZE);
}
Also used : FileStore(org.h2.store.FileStore) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream)

Example 4 with FileStoreInputStream

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

the class Recover method dumpLob.

private void dumpLob(String fileName, boolean lobCompression) {
    OutputStream fileOut = null;
    FileStore fileStore = null;
    long size = 0;
    String n = fileName + (lobCompression ? ".comp" : "") + ".txt";
    InputStream in = null;
    try {
        fileOut = FileUtils.newOutputStream(n, false);
        fileStore = FileStore.open(null, fileName, "r");
        fileStore.init();
        in = new FileStoreInputStream(fileStore, this, lobCompression, false);
        size = IOUtils.copy(in, fileOut);
    } catch (Throwable e) {
    // this is usually not a problem, because we try both compressed and
    // uncompressed
    } finally {
        IOUtils.closeSilently(fileOut);
        IOUtils.closeSilently(in);
        closeSilently(fileStore);
    }
    if (size == 0) {
        try {
            FileUtils.delete(n);
        } catch (Exception e) {
            traceError(n, e);
        }
    }
}
Also used : FileStore(org.h2.store.FileStore) FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) DbException(org.h2.message.DbException) SQLException(java.sql.SQLException) IOException(java.io.IOException)

Example 5 with FileStoreInputStream

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

the class ValueLob method getInputStream.

@Override
public InputStream getInputStream(long oneBasedOffset, long length) {
    if (fileName == null) {
        return super.getInputStream(oneBasedOffset, length);
    }
    FileStore store = handler.openFile(fileName, "r", true);
    boolean alwaysClose = SysProperties.lobCloseBetweenReads;
    InputStream inputStream = new BufferedInputStream(new FileStoreInputStream(store, handler, compressed, alwaysClose), Constants.IO_BUFFER_SIZE);
    return rangeInputStream(inputStream, oneBasedOffset, length, store.length());
}
Also used : FileStore(org.h2.store.FileStore) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) BufferedInputStream(java.io.BufferedInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) RangeInputStream(org.h2.store.RangeInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)6 FileStoreInputStream (org.h2.store.FileStoreInputStream)6 InputStream (java.io.InputStream)5 FileStore (org.h2.store.FileStore)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 IOException (java.io.IOException)4 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 OutputStream (java.io.OutputStream)1 SequenceInputStream (java.io.SequenceInputStream)1 SQLException (java.sql.SQLException)1 DbException (org.h2.message.DbException)1 RangeInputStream (org.h2.store.RangeInputStream)1