private void writeToFile(byte[] data) throws IOException { if (file == null) return; file.getParentFile().mkdirs(); FileOutputStream out = new FileOutputStream(file); try { out.write(data); } finally { CloseUtils.safeClose(out); } }
public DicomInputStream(File f) throws IOException { super(new BufferedInputStream(new FileInputStream(f))); try { this.ts = guessTransferSyntax(); } catch (IOException e) { CloseUtils.safeClose(this); throw e; } }
private void closeSocket() { if (state == State.STA13) { try { Thread.sleep(connector.getSocketCloseDelay()); } catch (InterruptedException e) { log.warn("Interrupted Socket Close Delay", e); } } setState(State.STA1); CloseUtils.safeClose(out); CloseUtils.safeClose(in); if (!closed) { log.info("{}: close {}", name, socket); CloseUtils.safeClose(socket); closed = true; onClosed(); } }
protected ImageReaderWriterFactory(String key, String def) { String val = System.getProperty(key, def); URL url; try { url = new URL(val); } catch (MalformedURLException e) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); if (cl == null || (url = cl.getResource(val)) == null) { if ((url = ImageReaderWriterFactory.class.getClassLoader() .getResource(val)) == null) { throw new ConfigurationError("missing resource: " + val); } } } InputStream is = null; try { is = url.openStream(); config.load(is); } catch (IOException e) { throw new ConfigurationError( "failed to load imageio configuration from " + url, e); } finally { CloseUtils.safeClose(is); } }
public static Object loadResource(String name) { ClassLoader cl = Thread.currentThread().getContextClassLoader(); InputStream is; if (cl == null || (is = cl.getResourceAsStream(name)) == null) { is = ResourceLocator.class.getClassLoader().getResourceAsStream( name); if (is == null) { throw new ConfigurationError("Missing Resource: " + name); } } try { ObjectInputStream ois = new ObjectInputStream(is); return ois.readObject(); } catch (Exception e) { throw new ConfigurationError("Failed to load Resource " + name, e); } finally { CloseUtils.safeClose(is); } }
+ url, e); } finally { CloseUtils.safeClose(in);
public static List<String> findResources(Class<?> c) { ArrayList<String> list = new ArrayList<String>(); try { for (Enumeration<URL> configs = enumResources(PREFIX + c.getName()); configs.hasMoreElements();) { URL u = configs.nextElement(); InputStream in = u.openStream(); try { BufferedReader r = new BufferedReader( new InputStreamReader(in, "utf-8")); String ln; while ((ln = r.readLine()) != null) { int end = ln.indexOf('#'); if (end >= 0) ln = ln.substring(0, end); ln = ln.trim(); if (ln.length() > 0) list.add(ln); } } finally { CloseUtils.safeClose(in); } } return list; } catch (IOException e) { throw new ConfigurationError("Failed to find Resources for " + c, e); } }
return; } finally { CloseUtils.safeClose(in);
return; } finally { CloseUtils.safeClose(in);
private DicomObject readDicomObject(TransferSyntax ts) throws IOException { DicomObject dcm = new BasicDicomObject(); DicomInputStream din = new DicomInputStream(this, ts); try { din.readDicomObject(dcm, -1); } catch (DicomCodingException e) { log.warn(as.toString() + ": Failed to decode dicom object: " + e.getMessage()); throw new AAbort(); } finally { CloseUtils.safeClose(din); } return dcm; }