package com.healthmarketscience.jackcess.impl;
+import java.io.Closeable;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
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.
} finally {
if(!success && closeChannel) {
// something blew up, shutdown the channel (quietly)
- try {
- channel.close();
- } catch(Exception ignored) {
- // we don't care
- }
+ ByteUtil.closeQuietly(channel);
}
}
}
} finally {
if(!success && closeChannel) {
// something blew up, shutdown the channel (quietly)
- try {
- channel.close();
- } catch(Exception ignored) {
- // we don't care
- }
+ ByteUtil.closeQuietly(channel);
}
}
}
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;
return tmpBytes;
} finally {
- if(contentStream != null) {
- try {
- contentStream.close();
- } catch(IOException e) {
- // ignored
- }
- }
+ ByteUtil.closeQuietly(contentStream);
}
}
return dataStream.toByteArray();
} finally {
- if(contentStream != null) {
- try {
- contentStream.close();
- } catch(IOException e) {
- // ignored
- }
- }
+ ByteUtil.closeQuietly(contentStream);
if(deflater != null) {
- deflater.end();
+ deflater.end();
}
}
}
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);
}
}
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;
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);
}
}