use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestAll method addTest.
private void addTest(TestBase test) {
// tests.add(test);
// run directly for now, because concurrently running tests
// fails on Raspberry Pi quite often (seems to be a JVM problem)
// event queue watchdog for tests that get stuck when running in Jenkins
final java.util.Timer watchdog = new java.util.Timer();
// 5 minutes
watchdog.schedule(new TimerTask() {
@Override
public void run() {
ThreadDeadlockDetector.dumpAllThreadsAndLocks("test watchdog timed out");
}
}, 5 * 60 * 1000);
try {
test.runTest(this);
} finally {
watchdog.cancel();
}
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestAll method testEverything.
/**
* Run all tests in all possible combinations.
*/
private void testEverything() throws SQLException {
for (int c = 0; c < 2; c++) {
if (c == 0) {
cipher = null;
} else {
cipher = "AES";
}
for (int a = 0; a < 64; a++) {
smallLog = (a & 1) != 0;
big = (a & 2) != 0;
networked = (a & 4) != 0;
memory = (a & 8) != 0;
ssl = (a & 16) != 0;
diskResult = (a & 32) != 0;
for (int trace = 0; trace < 3; trace++) {
traceLevelFile = trace;
test();
}
}
}
}
use of org.h2.dev.util.BinaryArithmeticStream.In 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.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class ValueLobDb method createTempClob.
/**
* Create a temporary CLOB value from a stream.
*
* @param in the reader
* @param length the number of characters to read, or -1 for no limit
* @param handler the data handler
* @return the lob value
*/
public static ValueLobDb createTempClob(Reader in, long length, DataHandler handler) {
if (length >= 0) {
// blocks the network level
try {
in = new RangeReader(in, 0, length);
} catch (IOException e) {
throw DbException.convert(e);
}
}
BufferedReader reader;
if (in instanceof BufferedReader) {
reader = (BufferedReader) in;
} else {
reader = new BufferedReader(in, Constants.IO_BUFFER_SIZE);
}
try {
boolean compress = handler.getLobCompressionAlgorithm(Value.CLOB) != null;
long remaining = Long.MAX_VALUE;
if (length >= 0 && length < remaining) {
remaining = length;
}
int len = getBufferSize(handler, compress, remaining);
char[] buff;
if (len >= Integer.MAX_VALUE) {
String data = IOUtils.readStringAndClose(reader, -1);
buff = data.toCharArray();
len = buff.length;
} else {
buff = new char[len];
reader.mark(len);
len = IOUtils.readFully(reader, buff, len);
}
if (len <= handler.getMaxLengthInplaceLob()) {
byte[] small = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8);
return ValueLobDb.createSmallLob(Value.CLOB, small, len);
}
reader.reset();
return new ValueLobDb(handler, reader, remaining);
} catch (IOException e) {
throw DbException.convertIOException(e, null);
}
}
use of org.h2.dev.util.BinaryArithmeticStream.In in project h2database by h2database.
the class TestMVRTree method testExample.
private void testExample() {
// create an in-memory store
MVStore s = MVStore.open(null);
// open an R-tree map
MVRTreeMap<String> r = s.openMap("data", new MVRTreeMap.Builder<String>());
// add two key-value pairs
// the first value is the key id (to make the key unique)
// then the min x, max x, min y, max y
r.add(new SpatialKey(0, -3f, -2f, 2f, 3f), "left");
r.add(new SpatialKey(1, 3f, 4f, 4f, 5f), "right");
// iterate over the intersecting keys
Iterator<SpatialKey> it = r.findIntersectingKeys(new SpatialKey(0, 0f, 9f, 3f, 6f));
for (SpatialKey k; it.hasNext(); ) {
k = it.next();
// System.out.println(k + ": " + r.get(k));
assertNotNull(k);
}
s.close();
}
Aggregations