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);
}
}
}
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);
}
}
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);
}
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);
}
}
}
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());
}
Aggregations