Java cleanup, close file handles when done with them
Change-Id: I79e6e0b8f53ae6f232c34aa8e833853d2ec24cf0
This commit is contained in:
@@ -184,6 +184,7 @@ public class GlobalFile {
|
||||
}
|
||||
}
|
||||
}
|
||||
inReader.close();
|
||||
}catch(Exception e){
|
||||
//showMessage();
|
||||
return null;//Uncertain data file error.
|
||||
|
@@ -511,42 +511,41 @@ public class java_fat implements TestBase
|
||||
return entryList;
|
||||
}
|
||||
|
||||
while (line != null)
|
||||
try
|
||||
{
|
||||
while (line != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!line.startsWith("#") && (line.length() > 1))
|
||||
{
|
||||
entryList.add(line.trim());
|
||||
}
|
||||
|
||||
line = exclusion.readLine();
|
||||
}
|
||||
catch (java.io.IOException ioe)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
System.out.println("Exception while reading exclusion list");
|
||||
}
|
||||
|
||||
return entryList;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!line.startsWith("#") && (line.length() > 1))
|
||||
{
|
||||
entryList.add(line.trim());
|
||||
}
|
||||
|
||||
line = exclusion.readLine();
|
||||
exclusion.close();
|
||||
}
|
||||
catch (java.io.IOException ioe)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
System.out.println("Exception while reading exclusion list");
|
||||
}
|
||||
|
||||
return entryList;
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
exclusion.close();
|
||||
}
|
||||
catch (java.io.IOException ioe)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
System.out.println("Couldn't close file " + url);
|
||||
}
|
||||
|
||||
return entryList;
|
||||
}
|
||||
|
||||
return entryList;
|
||||
}
|
||||
|
||||
|
@@ -42,6 +42,7 @@ public class FileUpdater {
|
||||
s.trim();
|
||||
xmlArray[count] = s;
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch( IOException ioe ) {
|
||||
String message = "\nError reading ProtocolHandler.xcu, please view SFrameworkInstall.log.";
|
||||
@@ -112,6 +113,7 @@ public class FileUpdater {
|
||||
s.trim();
|
||||
xmlArray[count] = s;
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch( IOException ioe ) {
|
||||
String message = "Error reading script.xlc, please view SFrameworkInstall.log.";
|
||||
@@ -184,6 +186,7 @@ public class FileUpdater {
|
||||
s.trim();
|
||||
xmlArray[count] = s;
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch( IOException ioe ) {
|
||||
|
||||
|
@@ -237,6 +237,7 @@ public class InstUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch( IOException ioe ) {
|
||||
System.out.println( "Error reading Netbeans location information" );
|
||||
@@ -285,6 +286,7 @@ public class InstUtil {
|
||||
jeditDetails[1] = version;
|
||||
}
|
||||
}
|
||||
reader.close();
|
||||
}
|
||||
catch( IOException ioe ) {
|
||||
System.out.println( "Error reading Jedit location information" );
|
||||
@@ -292,7 +294,6 @@ public class InstUtil {
|
||||
//catch( FileNotFoundException fnfe ) {
|
||||
//System.out.println( "Jedit activity.log FileNotFoundException" );
|
||||
//}
|
||||
|
||||
return jeditDetails;
|
||||
}
|
||||
|
||||
@@ -408,7 +409,7 @@ public class InstUtil {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reader.close();
|
||||
return results;
|
||||
}
|
||||
|
||||
|
@@ -21,13 +21,12 @@ package installer;
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
|
||||
public class ZipData
|
||||
{
|
||||
public class ZipData {
|
||||
public ZipData(String file) {
|
||||
}
|
||||
|
||||
public boolean extractEntry(String entry, String destination,
|
||||
JLabel statusLabel) {
|
||||
JLabel statusLabel) {
|
||||
|
||||
OutputStream out = null;
|
||||
InputStream in = null;
|
||||
@@ -35,23 +34,22 @@ public class ZipData
|
||||
System.out.println("Copying: " + entry);
|
||||
System.out.println("To: " + destination);
|
||||
|
||||
if (statusLabel != null) {
|
||||
statusLabel.setText("Copying " + entry);
|
||||
}
|
||||
if (statusLabel != null) {
|
||||
statusLabel.setText("Copying " + entry);
|
||||
}
|
||||
|
||||
String entryName;
|
||||
if (entry.lastIndexOf("/") != -1) {
|
||||
entryName = entry.substring(entry.lastIndexOf("/") + 1);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
entryName = entry;
|
||||
}
|
||||
|
||||
String destName;
|
||||
if (destination.lastIndexOf(File.separator) != -1) {
|
||||
destName = destination.substring(destination.lastIndexOf(File.separator) + 1);
|
||||
}
|
||||
else {
|
||||
destName = destination.substring(destination
|
||||
.lastIndexOf(File.separator) + 1);
|
||||
} else {
|
||||
destName = destination;
|
||||
}
|
||||
|
||||
@@ -60,20 +58,6 @@ public class ZipData
|
||||
|
||||
System.out.println("Unzipping " + entry + " to " + destination);
|
||||
|
||||
try {
|
||||
out = new FileOutputStream(destination);
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("Error opening " + destination +
|
||||
": " + ioe.getMessage());
|
||||
|
||||
if (statusLabel != null)
|
||||
statusLabel.setText("Error opening" + destination +
|
||||
"see SFramework.log for more information");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entry.startsWith("/") == false)
|
||||
entry = "/" + entry;
|
||||
|
||||
@@ -82,8 +66,21 @@ public class ZipData
|
||||
System.err.println("File " + entry + " not found in jar file");
|
||||
|
||||
if (statusLabel != null)
|
||||
statusLabel.setText("Failed extracting " + entry +
|
||||
"see SFramework.log for more information");
|
||||
statusLabel.setText("Failed extracting " + entry
|
||||
+ "see SFramework.log for more information");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
out = new FileOutputStream(destination);
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error opening " + destination + ": "
|
||||
+ ioe.getMessage());
|
||||
|
||||
if (statusLabel != null)
|
||||
statusLabel.setText("Error opening" + destination
|
||||
+ "see SFramework.log for more information");
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -94,22 +91,19 @@ public class ZipData
|
||||
|
||||
while ((len = in.read(bytes)) != -1)
|
||||
out.write(bytes, 0, len);
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
System.err.println("Error writing " + destination + ": " +
|
||||
ioe.getMessage());
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("Error writing " + destination + ": "
|
||||
+ ioe.getMessage());
|
||||
|
||||
if (statusLabel != null)
|
||||
statusLabel.setText("Failed writing " + destination +
|
||||
"see SFramework.log for more information");
|
||||
statusLabel.setText("Failed writing " + destination
|
||||
+ "see SFramework.log for more information");
|
||||
return false;
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
try {
|
||||
in.close();
|
||||
out.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
} catch (IOException ioe) {
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@@ -44,10 +44,9 @@ public class TestDataLoader {
|
||||
if (!f.exists())
|
||||
return;
|
||||
|
||||
BufferedReader in;
|
||||
|
||||
try {
|
||||
in = new BufferedReader(new FileReader(f));
|
||||
BufferedReader in = new BufferedReader(new FileReader(f));
|
||||
|
||||
String s, previous, current;
|
||||
ArrayList<Parameters> list = new ArrayList<Parameters>(11);
|
||||
@@ -59,6 +58,7 @@ public class TestDataLoader {
|
||||
list.add(getParameters(st));
|
||||
}
|
||||
else {
|
||||
in.close();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -77,6 +77,7 @@ public class TestDataLoader {
|
||||
}
|
||||
|
||||
tEnv.addObjRelation(previous, list);
|
||||
in.close();
|
||||
}
|
||||
catch (IOException ioe) {
|
||||
}
|
||||
|
@@ -113,16 +113,19 @@ public class ActiveSyncDriver {
|
||||
dataOut = conv.convert();
|
||||
}
|
||||
catch (Exception e) {
|
||||
fos.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (dataOut == null) {
|
||||
fos.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get the document and write it out.
|
||||
Document doc = (Document)dataOut.getDocumentEnumeration().next();
|
||||
if (doc == null) {
|
||||
fos.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -142,6 +142,7 @@ class MyHandler implements HttpHandler {
|
||||
byte[] data = new byte[(int) fileRequest.length()];
|
||||
FileInputStream fr = new FileInputStream(fileRequest);
|
||||
int count = fr.read(data);
|
||||
fr.close();
|
||||
|
||||
//set the Content-type header
|
||||
Headers h = xchange.getResponseHeaders();
|
||||
|
Reference in New Issue
Block a user