List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.streamsets.pipeline.lib.generator.DataGeneratorFactory.java
public DataGenerator getGenerator(File file) throws IOException { FileOutputStream fileOutputStream = null; try {/*from w w w .j av a2 s . c om*/ fileOutputStream = new FileOutputStream(file); return getGenerator(fileOutputStream); } catch (IOException ex) { throw ex; } finally { IOUtils.closeQuietly(fileOutputStream); } }
From source file:com.moz.fiji.hive.utils.FijiDataRequestSerializer.java
/** * Deserializes a data request./*from ww w .j a va2s. c o m*/ * * @param serialized A serialized data request. * @return A data request, or null if there is no data request in the given string. * @throws IOException If there is an IO error. */ public static FijiDataRequest deserialize(String serialized) throws IOException { final byte[] bytes = Base64.decodeBase64(serialized); final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); try { return (FijiDataRequest) ois.readObject(); } catch (ClassNotFoundException e) { throw new IOException(e); } finally { IOUtils.closeQuietly(ois); } }
From source file:com.ikon.util.Serializer.java
/** * @param obj//from w ww.ja v a 2s. c om */ public static byte[] write(Object obj) throws IOException { ByteArrayOutputStream baos = null; ObjectOutputStream oos = null; try { baos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(baos); oos.writeObject(obj); oos.flush(); baos.flush(); return baos.toByteArray(); } finally { IOUtils.closeQuietly(oos); IOUtils.closeQuietly(baos); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.logging.FileLoggerDestination.java
protected void log(final String message) throws LoggerException { try {/* w ww .j a va2s . c o m*/ if (this.writer == null) { //noinspection IOResourceOpenedButNotSafelyClosed this.writer = new PrintWriter(new BufferedWriter(new FileWriter(filename, append))); } writer.append(message); writer.flush(); } catch (IOException ioe) { throw new LoggerException(ioe); } finally { IOUtils.closeQuietly(writer); this.writer = null; } }
From source file:de.psdev.licensesdialog.licenses.License.java
protected String getContent(final Context context, final int contentResourceId) { InputStream inputStream = null; try {/* w w w . jav a 2 s .com*/ inputStream = context.getResources().openRawResource(contentResourceId); return IOUtils.toString(inputStream); } catch (IOException e) { Log.e("LicenseDialog", e.getMessage(), e); return ""; } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.norconex.importer.handler.splitter.impl.CsvSplitterTest.java
@After public void tearDown() throws IOException { IOUtils.closeQuietly(input); }
From source file:jp.xet.baseunits.tests.SerializationTester.java
/** * ????????/* w w w. java 2s .co m*/ * * @param serializable * @throws AssertionError ???? */ public static void assertCanBeSerialized(Object serializable) { if (Serializable.class.isInstance(serializable) == false) { fail("Object doesn't implement java.io.Serializable interface: " + serializable.getClass()); } ObjectOutputStream out = null; ObjectInputStream in = null; ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream(); ByteArrayInputStream byteArrayIn = null; try { out = new ObjectOutputStream(byteArrayOut); out.writeObject(serializable); byteArrayIn = new ByteArrayInputStream(byteArrayOut.toByteArray()); in = new ObjectInputStream(byteArrayIn); Object deserialized = in.readObject(); if (serializable.equals(deserialized) == false) { fail("Reconstituted object is expected to be equal to serialized"); } } catch (IOException e) { fail(e.getMessage()); } catch (ClassNotFoundException e) { fail(e.getMessage()); } finally { IOUtils.closeQuietly(out); IOUtils.closeQuietly(in); } }
From source file:com.alibaba.simpleimage.render.ReadRenderTest.java
/** * Test method for {@link com.alibaba.simpleimage.render.ReadRender#ReadRender(java.io.InputStream, boolean)}. *//*from w w w . java2s.co m*/ public void testReadRenderInputStreamBoolean() throws Exception { File file = new File(path, "334.jpg"); InputStream input = null; ImageWrapper img = null; ImageRender rr = null; try { input = new FileInputStream(file); rr = new ReadRender(input, true); img = rr.render(); assertNotNull(img); } finally { IOUtils.closeQuietly(input); if (rr != null) { rr.dispose(); } } }
From source file:io.apiman.manager.api.micro.Users.java
public static final List<User> getUsers() throws Exception { List<User> rval = new ArrayList<>(); URL usersUrl = getUsersUrl(); if (usersUrl != null) { System.out.println("Loading users from: " + usersUrl); InputStream in = null;/* w w w . j av a2s . c o m*/ BufferedReader reader = null; try { in = usersUrl.openStream(); reader = new BufferedReader(new InputStreamReader(in)); String line = reader.readLine(); while (line != null) { line = line.trim(); if (line.length() == 0 || line.startsWith("#")) { continue; } String[] split = line.split(","); User user = new User(); user.setId(split[0]); user.setPassword(split[1]); user.getRoles().add("apiuser"); boolean isAdmin = "true".equals(split[2]); if (isAdmin) { user.getRoles().add("apiadmin"); } rval.add(user); System.out.println(" added user => " + user.getId()); line = reader.readLine(); } } catch (Throwable t) { throw new RuntimeException(t); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(reader); } } else { System.out.println("Using default users."); User user = new User(); user.setId("admin"); user.setPassword("admin123!"); user.getRoles().add("apiuser"); user.getRoles().add("apiadmin"); rval.add(user); } return rval; }
From source file:com.mgmtp.jfunk.data.source.CsvDataSourceTest.java
/** * This method is annotated with {@link BeforeMethod}, because we need a fresh data source for * every test./*from w w w . java 2 s . c o m*/ */ @BeforeMethod public void setUp() throws IOException { Configuration config = new Configuration(Charsets.UTF_8); InputStream is = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test-datasources.properties"); config.load(is); } finally { IOUtils.closeQuietly(is); } ds = new CsvDataSource(config); }