diff options
author | Adam Domurad <[email protected]> | 2013-06-03 10:51:47 -0400 |
---|---|---|
committer | Adam Domurad <[email protected]> | 2013-06-03 10:51:47 -0400 |
commit | 0fa3a1ac219c218d2c489b10c8ce70a108c50b10 (patch) | |
tree | 1a0f76ff7f7413e12328a2f6be1ab7df44bfe413 /netx | |
parent | 58464afe42ef3f0558da034bece3a7800f9104ff (diff) |
Add NativeLibraryStorageTEst
Diffstat (limited to 'netx')
-rw-r--r-- | netx/net/sourceforge/jnlp/cache/NativeLibraryStorage.java | 8 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/util/StreamUtils.java | 22 |
2 files changed, 23 insertions, 7 deletions
diff --git a/netx/net/sourceforge/jnlp/cache/NativeLibraryStorage.java b/netx/net/sourceforge/jnlp/cache/NativeLibraryStorage.java index ef0bd82..7d9eb6e 100644 --- a/netx/net/sourceforge/jnlp/cache/NativeLibraryStorage.java +++ b/netx/net/sourceforge/jnlp/cache/NativeLibraryStorage.java @@ -76,6 +76,8 @@ public class NativeLibraryStorage { return null; } + public static final String[] NATIVE_LIBRARY_EXTENSIONS = { ".so", ".dylib", ".jnilib", ".framework", ".dll" }; + /** * Search for and enable any native code contained in a JAR by copying the * native files into the filesystem. Called in the security context of the @@ -89,8 +91,6 @@ public class NativeLibraryStorage { if (localFile == null) return; - String[] librarySuffixes = { ".so", ".dylib", ".jnilib", ".framework", ".dll" }; - try { JarFile jarFile = new JarFile(localFile, false); Enumeration<JarEntry> entries = jarFile.entries(); @@ -105,7 +105,7 @@ public class NativeLibraryStorage { String name = new File(e.getName()).getName(); boolean isLibrary = false; - for (String suffix : librarySuffixes) { + for (String suffix : NATIVE_LIBRARY_EXTENSIONS) { if (name.endsWith(suffix)) { isLibrary = true; break; @@ -132,7 +132,7 @@ public class NativeLibraryStorage { } } - private void ensureNativeStoreDirectory() { + void ensureNativeStoreDirectory() { if (jarEntryDirectory == null) { jarEntryDirectory = createNativeStoreDirectory(); addSearchDirectory(jarEntryDirectory); diff --git a/netx/net/sourceforge/jnlp/util/StreamUtils.java b/netx/net/sourceforge/jnlp/util/StreamUtils.java index c498b7b..294944a 100644 --- a/netx/net/sourceforge/jnlp/util/StreamUtils.java +++ b/netx/net/sourceforge/jnlp/util/StreamUtils.java @@ -42,16 +42,17 @@ import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.io.OutputStream; public class StreamUtils { - /*** + /** * Closes a stream, without throwing IOException. * In case of IOException, prints the stack trace to System.err. * * @param stream the stream that will be closed */ - public static void closeSilently (Closeable stream) { + public static void closeSilently(Closeable stream) { if (stream != null) { try { stream.close(); @@ -61,8 +62,23 @@ public class StreamUtils { } } + /** + * Copy an input stream's contents into an output stream. + */ + public static void copyStream(InputStream input, OutputStream output) + throws IOException { + byte[] buffer = new byte[1024]; + while (true) { + int bytesRead = input.read(buffer); + if (bytesRead == -1) { + break; + } + output.write(buffer, 0, bytesRead); + } + } - public static String readStreamAsString(InputStream stream) throws IOException { + public static String readStreamAsString(InputStream stream) + throws IOException { InputStreamReader is = new InputStreamReader(stream); StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader(is); |