#131: Close version file stream

This commit is contained in:
Taro L. Saito 2016-01-22 18:34:10 +09:00
parent 1198363176
commit e029c0e560

View File

@ -25,6 +25,7 @@
package org.xerial.snappy; package org.xerial.snappy;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
@ -282,20 +283,28 @@ public class Snappy
*/ */
public static String getNativeLibraryVersion() public static String getNativeLibraryVersion()
{ {
URL versionFile = SnappyLoader.class.getResource("/org/xerial/snappy/VERSION"); URL versionFile = SnappyLoader.class.getResource("/org/xerial/snappy/VERSION");
String version = "unknown"; String version = "unknown";
try { try {
if (versionFile != null) { if (versionFile != null) {
InputStream in = null;
try {
Properties versionData = new Properties(); Properties versionData = new Properties();
versionData.load(versionFile.openStream()); in = versionFile.openStream();
versionData.load(in);
version = versionData.getProperty("version", version); version = versionData.getProperty("version", version);
if (version.equals("unknown")) { if (version.equals("unknown")) {
version = versionData.getProperty("VERSION", version); version = versionData.getProperty("VERSION", version);
} }
version = version.trim().replaceAll("[^0-9\\.]", ""); version = version.trim().replaceAll("[^0-9\\.]", "");
} }
finally {
if(in != null) {
in.close();
}
}
}
} }
catch (IOException e) { catch (IOException e) {
e.printStackTrace(); e.printStackTrace();