git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@796 f203690c-595d-4dc9-a70b-905162fa7fd2tags/jackcess-2.0.1
@@ -27,6 +27,7 @@ King of Prussia, PA 19406 | |||
package com.healthmarketscience.jackcess.impl; | |||
import java.io.Closeable; | |||
import java.io.FileWriter; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
@@ -607,6 +608,17 @@ public final class ByteUtil { | |||
return newArr; | |||
} | |||
/** | |||
* Closes the given Closeable if non-null, swallows any IOExceptions. | |||
*/ | |||
public static void closeQuietly(Closeable c) { | |||
if(c != null) { | |||
try { | |||
c.close(); | |||
} catch(IOException ignored) {} | |||
} | |||
} | |||
/** | |||
* Utility byte stream similar to ByteArrayOutputStream but with extended | |||
* accessibility to the bytes. |
@@ -391,11 +391,7 @@ public class DatabaseImpl implements Database | |||
} finally { | |||
if(!success && closeChannel) { | |||
// something blew up, shutdown the channel (quietly) | |||
try { | |||
channel.close(); | |||
} catch(Exception ignored) { | |||
// we don't care | |||
} | |||
ByteUtil.closeQuietly(channel); | |||
} | |||
} | |||
} | |||
@@ -449,11 +445,7 @@ public class DatabaseImpl implements Database | |||
} finally { | |||
if(!success && closeChannel) { | |||
// something blew up, shutdown the channel (quietly) | |||
try { | |||
channel.close(); | |||
} catch(Exception ignored) { | |||
// we don't care | |||
} | |||
ByteUtil.closeQuietly(channel); | |||
} | |||
} | |||
} |
@@ -347,13 +347,7 @@ public class GeneralLegacyIndexCodes { | |||
throw new RuntimeException("failed loading index codes file " + | |||
codesFilePath, e); | |||
} finally { | |||
if (reader != null) { | |||
try { | |||
reader.close(); | |||
} catch (IOException ex) { | |||
// ignored | |||
} | |||
} | |||
ByteUtil.closeQuietly(reader); | |||
} | |||
return values; |
@@ -404,13 +404,7 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment> | |||
return tmpBytes; | |||
} finally { | |||
if(contentStream != null) { | |||
try { | |||
contentStream.close(); | |||
} catch(IOException e) { | |||
// ignored | |||
} | |||
} | |||
ByteUtil.closeQuietly(contentStream); | |||
} | |||
} | |||
@@ -465,15 +459,9 @@ public class AttachmentColumnInfoImpl extends ComplexColumnInfoImpl<Attachment> | |||
return dataStream.toByteArray(); | |||
} finally { | |||
if(contentStream != null) { | |||
try { | |||
contentStream.close(); | |||
} catch(IOException e) { | |||
// ignored | |||
} | |||
} | |||
ByteUtil.closeQuietly(contentStream); | |||
if(deflater != null) { | |||
deflater.end(); | |||
deflater.end(); | |||
} | |||
} | |||
} |
@@ -220,13 +220,7 @@ public class ExportUtil { | |||
exportWriter(db, tableName, out, header, delim, quote, filter); | |||
out.close(); | |||
} finally { | |||
if (out != null) { | |||
try { | |||
out.close(); | |||
} catch (Exception ex) { | |||
LOG.warn("Could not close file " + f.getAbsolutePath(), ex); | |||
} | |||
} | |||
ByteUtil.closeQuietly(out); | |||
} | |||
} | |||
@@ -46,6 +46,7 @@ import com.healthmarketscience.jackcess.DataType; | |||
import com.healthmarketscience.jackcess.Database; | |||
import com.healthmarketscience.jackcess.Table; | |||
import com.healthmarketscience.jackcess.TableBuilder; | |||
import com.healthmarketscience.jackcess.impl.ByteUtil; | |||
import org.apache.commons.logging.Log; | |||
import org.apache.commons.logging.LogFactory; | |||
@@ -315,13 +316,7 @@ public class ImportUtil | |||
return importReader(in, db, name, delim, quote, filter, | |||
useExistingTable, header); | |||
} finally { | |||
if (in != null) { | |||
try { | |||
in.close(); | |||
} catch (IOException ex) { | |||
LOG.warn("Could not close file " + f.getAbsolutePath(), ex); | |||
} | |||
} | |||
ByteUtil.closeQuietly(in); | |||
} | |||
} | |||