Tabnine Logo
CloseUtils
Code IndexAdd Tabnine to your IDE (free)

How to use
CloseUtils
in
org.dcm4che2.util

Best Java code snippets using org.dcm4che2.util.CloseUtils (Showing top 17 results out of 315)

origin: dcm4che/dcm4che-core

  public static void serializeTo(Object o, File out) throws IOException {
    FileOutputStream fos = new FileOutputStream(out);
    ObjectOutputStream oos = null;
    try {
      oos = new ObjectOutputStream(fos);
      oos.writeObject(o);
    } finally {
      CloseUtils.safeClose(oos);
      CloseUtils.safeClose(fos);
    }
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely close, absorbing exceptions and handling <code>null</code>
 * graciously.
 * 
 * @param object object to close.
 */
public static void safeClose(Closeable object) {
  try {
    if (object != null) {
      object.close();
    }
  } catch (IOException e) {
    log(object, e);
  }
}
origin: dcm4che/dcm4che-core

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);
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely close a socket, absorbing exceptions and handling
 * <code>null</code> graciously.
 * 
 * @param socket object to close.
 */
public static void safeClose(Socket socket) {
  try {
    if (socket != null) {
      socket.close();
    }
  } catch (IOException e) {
    log(socket, e);
  }
}
origin: dcm4che/dcm4che-core

public DicomInputStream(File f) throws IOException {
  super(new BufferedInputStream(new FileInputStream(f)));
  try {
    this.ts = guessTransferSyntax();
  } catch (IOException e) {
    CloseUtils.safeClose(this);
    throw e;
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely close a JDBC Statement, absorbing exceptions and handling
 * <code>null</code> graciously.
 * 
 * @param statement
 *            to close.
 */
public static void safeClose(Statement statement) {
  try {
    if (statement != null) {
      statement.close();
    }
  } catch (SQLException e) {
    log(statement, e);
  }
}
origin: dcm4che/dcm4che-net

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();
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely close a server socket, absorbing exceptions and handling
 * <code>null</code> graciously.
 * 
 * @param socket object to close.
 */
public static void safeClose(ServerSocket socket) {
  try {
    if (socket != null) {
      socket.close();
    }
  } catch (IOException e) {
    log(socket, e);
  }
}
origin: dcm4che/dcm4che-imageio

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);
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely flush, absorbing smells, sounds, exceptions and handling <code>null</code>
 * graciously.
 * 
 * @param object object to close.
 */
public static void safeFlush(Flushable object) {
  try {
    if (object != null) {
      object.flush();
    }
  } catch (IOException e) {
    log(object, e);
  }
}
origin: dcm4che/dcm4che-core

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);
  }
}
origin: dcm4che/dcm4che-core

/**
 * Safely close an ImageInputStream stream, absorbing exceptions and
 * handling <code>null</code> graciously.
 * 
 * @param is to close.
 */
public static void safeClose(ImageInputStream is) {
  try {
    if (is != null) {
      is.close();
    }
  } catch (IOException e) {
    log(is, e);
  }
}
 
origin: dcm4che/dcm4che-core

      + url, e);
} finally {
  CloseUtils.safeClose(in);
origin: dcm4che/dcm4che-core

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);
  }
}
origin: bioinformatics-ua/dicoogle

  return;
} finally {
  CloseUtils.safeClose(in);
origin: bioinformatics-ua/dicoogle

  return;
} finally {
  CloseUtils.safeClose(in);
origin: dcm4che/dcm4che-net

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;
}
org.dcm4che2.utilCloseUtils

Most used methods

  • safeClose
    Safely close an ImageInputStream stream, absorbing exceptions and handling null graciously.
  • log

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • findViewById (Activity)
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • BigInteger (java.math)
    An immutable arbitrary-precision signed integer.FAST CRYPTOGRAPHY This implementation is efficient f
  • Stream (java.util.stream)
    A sequence of elements supporting sequential and parallel aggregate operations. The following exampl
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • JTable (javax.swing)
  • Option (scala)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now