Fixed some minor potential resource leaks.

This commit is contained in:
Ian Brandt 2012-10-30 23:26:21 -07:00
parent 0d24df7628
commit 35f04b4df6
2 changed files with 45 additions and 32 deletions

View File

@ -67,8 +67,11 @@ public class TsvToJson
}
}
BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), Charsets.UTF_8));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), Charsets.UTF_8));
BufferedReader in = null;
BufferedWriter out = null;
try {
in = new BufferedReader(new InputStreamReader(new FileInputStream(inFile), Charsets.UTF_8));
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile), Charsets.UTF_8));
String line = null;
int count = 0;
long currTime = System.currentTimeMillis();
@ -101,9 +104,15 @@ public class TsvToJson
}
System.out.printf("Completed %,d lines in %,d millis.%n", count, System.currentTimeMillis() - startTime);
out.flush();
} finally {
if (out != null) {
out.close();
}
if (in != null) {
in.close();
}
}
}
public static interface FieldHandler
{

View File

@ -416,9 +416,11 @@ public class IndexMerger
long startTime = System.currentTimeMillis();
File indexFile = new File(outDir, "index.drd");
FileOutputStream fileOutputStream = null;
FileChannel channel = null;
try {
channel = new FileOutputStream(indexFile).getChannel();
fileOutputStream = new FileOutputStream(indexFile);
channel = fileOutputStream.getChannel();
channel.write(ByteBuffer.wrap(new byte[]{IndexIO.CURRENT_VERSION_ID}));
GenericIndexed.fromIterable(mergedDimensions, GenericIndexed.stringStrategy).writeToChannel(channel);
@ -438,6 +440,8 @@ public class IndexMerger
finally {
Closeables.closeQuietly(channel);
channel = null;
Closeables.closeQuietly(fileOutputStream);
fileOutputStream = null;
}
IndexIO.checkFileSize(indexFile);
log.info("outDir[%s] completed index.drd in %,d millis.", outDir, System.currentTimeMillis() - startTime);