Changeset: 9f42bf385149 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f42bf385149
Modified Files:
java/embedded/src/main/java/org/monetdb/embedded/MonetDBEmbedded.java
Branch: embedded-java
Log Message:
Use smalled buffer size when streaming out the lib
The bootstrap is slower now, but uses a lot less memory, also safer. So being
conservative here.
While there, added a few comments to explain what's going on.
Note: if the in stream is null, we can just load the unpacked file, but I
wanted to stream it out as well, verifying the stream copy the lib and load
behaviour every time. You might want to change that, if building + testing
tends to take too long (due to the rather small buffer). Or just increase the
buffer size again.
diffs (29 lines):
diff --git
a/java/embedded/src/main/java/org/monetdb/embedded/MonetDBEmbedded.java
b/java/embedded/src/main/java/org/monetdb/embedded/MonetDBEmbedded.java
--- a/java/embedded/src/main/java/org/monetdb/embedded/MonetDBEmbedded.java
+++ b/java/embedded/src/main/java/org/monetdb/embedded/MonetDBEmbedded.java
@@ -64,16 +64,20 @@ public class MonetDBEmbedded implements
try {
InputStream in =
MonetDBEmbedded.class.getResourceAsStream(File.separatorChar + pathToLib);
if (in == null) {
+ // OK, the input stream is null, hence no .jar
+ // This was probably a test and/or in an IDE
+ // Just read the files from the
src/main/resources/lib dir
in = new FileInputStream(new File(pathToLib));
}
- byte[] buffer = new byte[in.available()];
- in.read(buffer);
- in.close();
- // Extract it in a temp location
+ // Set a temp location to extract (and load from later)
final Path tempLibsDir =
Files.createTempDirectory("monetdb-embedded-libs");
File fileOut = new File(tempLibsDir.toString() +
File.separatorChar + fileName);
try (OutputStream out = new FileOutputStream(fileOut)) {
- out.write(buffer);
+ int buffer;
+ while ((buffer = in.read()) != -1) {
+ out.write(buffer);
+ }
+ in.close();
// Load the lib from the extracted file
System.load(fileOut.toString());
}
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list