Java Code Examples for java.io.Closeable

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project hackergarten-moreunit, under directory /org.moreunit.core.test/test/org/moreunit/core/util/.

Source file: IOUtilsTest.java

  18 
vote

@Test public void closeQuietly_should_close_resources() throws Exception {
  Closeable closeable1=mock(Closeable.class);
  Closeable closeable2=mock(Closeable.class);
  closeQuietly(closeable1,closeable2);
  verify(closeable1,times(1)).close();
  verify(closeable2,times(1)).close();
}
 

Example 2

From project hadoop_framework, under directory /core/src/test/java/com/lightboxtechnologies/io/.

Source file: IOUtilsTest.java

  18 
vote

@Test public void testCloseQuietlyCloseableOk() throws IOException {
  final Closeable c=context.mock(Closeable.class);
  context.checking(new Expectations(){
{
      oneOf(c).close();
    }
  }
);
  IOUtils.closeQuietly(c);
}
 

Example 3

From project jboss-polyglot, under directory /core/src/main/java/org/projectodd/polyglot/core/processors/.

Source file: ArchiveDirectoryMountingProcessor.java

  18 
vote

protected void mountDir(DeploymentUnit unit,VirtualFile root,String name,String path) throws IOException {
  VirtualFile logical=root.getChild(name);
  File physical=new File(path);
  physical.mkdirs();
  Closeable mount=VFS.mountReal(physical,logical);
  unit.addToAttachmentList(CLOSEABLE_ATTACHMENTS_KEY,mount);
}
 

Example 4

From project jboss-vfs, under directory /src/main/java/org/jboss/vfs/.

Source file: VFS.java

  18 
vote

private static MountHandle doMount(final FileSystem fileSystem,final VirtualFile mountPoint,Closeable... additionalCloseables) throws IOException {
  boolean ok=false;
  try {
    final Closeable mountHandle=mount(mountPoint,fileSystem);
    ok=true;
    return new BasicMountHandle(fileSystem,mountHandle,additionalCloseables);
  }
  finally {
    if (!ok) {
      VFSUtils.safeClose(fileSystem);
    }
  }
}
 

Example 5

From project cloudify, under directory /dsl/src/main/java/org/cloudifysource/dsl/internal/packaging/.

Source file: ZipUtils.java

  17 
vote

/** 
 * Zips a directory into the given file.
 * @param directory the directory to zip.
 * @param zipfile the zip file to create.
 * @throws IOException in case of an error.
 */
public static void zip(final File directory,final File zipfile) throws IOException {
  final URI base=directory.toURI();
  final File toZip=new File(zipfile,"");
  toZip.setWritable(true);
  final Stack<File> stack=new Stack<File>();
  stack.push(directory);
  final OutputStream out=new FileOutputStream(toZip);
  Closeable res=out;
  try {
    final ZipOutputStream zout=new ZipOutputStream(out);
    res=zout;
    while (!stack.isEmpty()) {
      final File currentDirectory=stack.pop();
      for (      final File kid : currentDirectory.listFiles()) {
        String name=base.relativize(kid.toURI()).getPath();
        if (kid.isDirectory()) {
          stack.push(kid);
          name=name.endsWith("/") ? name : name + "/";
          zout.putNextEntry(new ZipEntry(name));
        }
 else {
          zout.putNextEntry(new ZipEntry(name));
          copy(kid,zout);
          zout.closeEntry();
        }
      }
    }
  }
  finally {
    res.close();
  }
}
 

Example 6

From project commons-io, under directory /src/test/java/org/apache/commons/io/.

Source file: IOUtilsTestCase.java

  17 
vote

public void testCloseableCloseQuietlyOnException(){
  IOUtils.closeQuietly(new Closeable(){
    public void close() throws IOException {
      throw new IOException();
    }
  }
);
}
 

Example 7

From project crash, under directory /shell/core/src/test/java/org/crsh/processor/term/.

Source file: AbstractProcessorTestCase.java

  17 
vote

public void testTermClose() throws Exception {
  final AtomicBoolean closed=new AtomicBoolean();
  processor.addListener(new Closeable(){
    public void close() throws IOException {
      closed.set(true);
    }
  }
);
  term.publish(TermEvent.close());
  assertJoin(thread);
  assertTrue(closed.get());
}
 

Example 8

From project fastjson, under directory /src/test/java/com/alibaba/json/bvt/parser/.

Source file: IOUtilsTest.java

  17 
vote

public void test_close1() throws Exception {
  IOUtils.close(new Closeable(){
    public void close() throws IOException {
    }
  }
);
}
 

Example 9

From project gxa, under directory /atlas-web/src/main/java/ae3/model/.

Source file: ExperimentalData.java

  17 
vote

/** 
 * Empty class from the start, one should fill it with addXX and setXX methods
 * @param experimentWithData the containing experiment
 */
public ExperimentalData(ExperimentWithData experimentWithData) throws AtlasDataException {
  log.info("loading data for experiment" + experimentWithData.getExperiment().getAccession());
  this.experimentWithData=experimentWithData;
  ResourceWatchdogFilter.register(new Closeable(){
    public void close(){
      closeQuietly(ExperimentalData.this.experimentWithData);
    }
  }
);
  collectSamples();
  collectAssays();
  createAssaySampleMappings();
}
 

Example 10

From project android-rackspacecloud, under directory /extensions/apachehc/src/main/java/org/jclouds/http/apachehc/config/.

Source file: ApacheHCHttpCommandExecutorServiceModule.java

  16 
vote

@Singleton @Provides ClientConnectionManager newClientConnectionManager(HttpParams params,X509HostnameVerifier verifier,Closer closer) throws NoSuchAlgorithmException, KeyManagementException {
  SchemeRegistry schemeRegistry=new SchemeRegistry();
  Scheme http=new Scheme("http",PlainSocketFactory.getSocketFactory(),80);
  SSLContext context=SSLContext.getInstance("TLS");
  context.init(null,null,null);
  SSLSocketFactory sf=new SSLSocketFactory(context);
  sf.setHostnameVerifier(verifier);
  Scheme https=new Scheme("https",sf,443);
  SchemeRegistry sr=new SchemeRegistry();
  sr.register(http);
  sr.register(https);
  schemeRegistry.register(new Scheme("http",PlainSocketFactory.getSocketFactory(),80));
  schemeRegistry.register(new Scheme("https",SSLSocketFactory.getSocketFactory(),443));
  final ClientConnectionManager cm=new ThreadSafeClientConnManager(params,schemeRegistry);
  closer.addToClose(new Closeable(){
    @Override public void close() throws IOException {
      cm.shutdown();
    }
  }
);
  return cm;
}
 

Example 11

From project accent, under directory /src/test/java/net/lshift/accent/.

Source file: ConnectionSmokeTest.java

  15 
vote

private static void closeQuietly(Closeable c){
  try {
    c.close();
  }
 catch (  IOException e) {
  }
}
 

Example 12

From project aether-core, under directory /aether-impl/src/main/java/org/eclipse/aether/internal/impl/.

Source file: DefaultFileProcessor.java

  15 
vote

private static void close(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 13

From project akubra, under directory /akubra-core/src/main/java/org/akubraproject/impl/.

Source file: StreamManager.java

  15 
vote

/** 
 * Creates an instance.
 */
public StreamManager(){
  listener=new CloseListener(){
    public void notifyClosed(    Closeable closeable){
      if (closeable instanceof InputStream) {
synchronized (openInputStreams) {
          openInputStreams.remove(closeable);
          openInputStreams.notifyAll();
        }
      }
 else {
synchronized (openOutputStreams) {
          openOutputStreams.remove(closeable);
          openOutputStreams.notifyAll();
        }
      }
    }
  }
;
}
 

Example 14

From project AmDroid, under directory /httpclientandroidlib/src/ch/boye/httpclientandroidlib/impl/client/cache/.

Source file: IOUtils.java

  15 
vote

static void closeSilently(final Closeable closable){
  try {
    closable.close();
  }
 catch (  IOException ignore) {
  }
}
 

Example 15

From project andlytics, under directory /src/com/github/andlyticsproject/util/.

Source file: Utils.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c != null) {
    try {
      c.close();
    }
 catch (    Exception e) {
    }
  }
}
 

Example 16

From project android-cropimage, under directory /src/com/android/camera/.

Source file: Util.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 17

From project Android-Simple-Social-Sharing, under directory /SimpleSocialSharing/src/com/nostra13/socialsharing/twitter/extpack/winterwell/jtwitter/.

Source file: InternalUtils.java

  15 
vote

public static void close(Closeable strm){
  try {
    strm.close();
  }
 catch (  IOException e) {
  }
}
 

Example 18

From project android-xbmcremote, under directory /src/org/xbmc/android/util/.

Source file: IOUtilities.java

  15 
vote

/** 
 * Closes the specified stream.
 * @param stream The stream to close.
 */
public static void closeStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
      android.util.Log.e(LOG_TAG,"Could not close stream",e);
    }
  }
}
 

Example 19

From project AndroidDevWeekendDub-BookLibrary, under directory /src/org/curiouscreature/android/shelves/util/.

Source file: IOUtilities.java

  15 
vote

/** 
 * Closes the specified stream.
 * @param stream The stream to close.
 */
public static void closeStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
      android.util.Log.e(LOG_TAG,"Could not close stream",e);
    }
  }
}
 

Example 20

From project androidquery, under directory /src/com/androidquery/util/.

Source file: AQUtility.java

  15 
vote

public static void close(Closeable c){
  try {
    if (c != null) {
      c.close();
    }
  }
 catch (  Exception e) {
  }
}
 

Example 21

From project android_external_guava, under directory /src/com/google/common/io/.

Source file: AppendableWriter.java

  15 
vote

@Override public void close() throws IOException {
  this.closed=true;
  if (target instanceof Closeable) {
    ((Closeable)target).close();
  }
}
 

Example 22

From project android_packages_apps_Gallery, under directory /src/com/android/camera/.

Source file: MenuHelper.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c != null) {
    try {
      c.close();
    }
 catch (    Throwable e) {
    }
  }
}
 

Example 23

From project android_packages_apps_Gallery2, under directory /gallerycommon/src/com/android/gallery3d/common/.

Source file: BlobCache.java

  15 
vote

static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 24

From project android_packages_apps_Gallery3D, under directory /src/com/cooliris/media/.

Source file: Util.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 25

From project ant4eclipse, under directory /org.ant4eclipse.lib.core/src/org/ant4eclipse/lib/core/util/.

Source file: Utilities.java

  15 
vote

/** 
 * Closes the supplied Closeable if it's available.
 * @param closeable The closeable that has to be closed. Maybe <code>null</code>.
 */
public static final void close(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException ex) {
      A4ELogging.warn(ex.getMessage());
    }
  }
}
 

Example 26

From project any23, under directory /core/src/main/java/org/apache/any23/util/.

Source file: StreamUtils.java

  15 
vote

/** 
 * Closes the closable interface and reports error if any.
 * @param closable the closable object to be closed.
 */
public static void closeGracefully(Closeable closable){
  if (closable != null) {
    try {
      closable.close();
    }
 catch (    Exception e) {
      logger.error("Error while closing object " + closable,e);
    }
  }
}
 

Example 27

From project apps-for-android, under directory /Amazed/src/com/example/amazed/.

Source file: Maze.java

  15 
vote

/** 
 * Closes the specified stream.
 * @param stream The stream to close.
 */
private static void closeStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 28

From project archive-commons, under directory /archive-commons/src/main/java/org/archive/util/.

Source file: IAUtils.java

  15 
vote

public static void closeQuietly(Object input){
  if (input == null || !(input instanceof Closeable)) {
    return;
  }
  try {
    ((Closeable)input).close();
  }
 catch (  IOException ioe) {
  }
}
 

Example 29

From project ardverk-commons, under directory /src/main/java/org/ardverk/io/.

Source file: IoUtils.java

  15 
vote

/** 
 * Closes the given  {@code Object}. Returns  {@code true} on successand  {@code false} on failure. All {@link IOException}s will be caught and no error will be thrown if the Object isn't any of the supported types.
 * @see Closeable
 * @see #close(Closeable)
 * @see AutoCloseable
 * @see #close(AutoCloseable)
 * @see Socket
 * @see #close(Socket)
 * @see ServerSocket
 * @see #close(ServerSocket)
 * @see DatagramSocket
 * @see #close(DatagramSocket)
 * @see AtomicReference
 * @see #close(AtomicReference)
 */
public static boolean close(Object o){
  if (o instanceof Closeable) {
    return close((Closeable)o);
  }
 else   if (o instanceof AutoCloseable) {
    return close((AutoCloseable)o);
  }
 else   if (o instanceof Socket) {
    return close((Socket)o);
  }
 else   if (o instanceof ServerSocket) {
    return close((ServerSocket)o);
  }
 else   if (o instanceof DatagramSocket) {
    return close((DatagramSocket)o);
  }
 else   if (o instanceof AtomicReference<?>) {
    return close(((AtomicReference<?>)o));
  }
  return false;
}
 

Example 30

From project arquillian-container-tomcat, under directory /tomcat-common/src/main/java/org/jboss/arquillian/container/tomcat/.

Source file: IOUtil.java

  15 
vote

/** 
 * Closes an closeable instance ignoring exceptions
 * @param closeable the closeable to be closed
 */
public static void closeQuietly(Closeable closeable){
  try {
    if (closeable != null) {
      closeable.close();
    }
  }
 catch (  final IOException ignore) {
  }
}
 

Example 31

From project aws-maven, under directory /src/main/java/org/springframework/build/aws/maven/.

Source file: IoUtils.java

  15 
vote

static void closeQuietly(Closeable... closeables){
  for (  Closeable closeable : closeables) {
    if (closeable != null) {
      try {
        closeable.close();
      }
 catch (      IOException e) {
      }
    }
  }
}
 

Example 32

From project aws-tasks, under directory /src/main/java/datameer/awstasks/util/.

Source file: IoUtil.java

  15 
vote

public static void closeQuietly(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    Throwable e) {
      LOG.warn("failed to close '" + closeable + "'",e);
    }
  }
}
 

Example 33

From project bagheera, under directory /src/main/java/com/mozilla/bagheera/util/.

Source file: ShutdownHook.java

  15 
vote

private ShutdownHook(){
  Runtime.getRuntime().addShutdownHook(new Thread(){
    public void run(){
      for (      Closeable c : closeables) {
        try {
          c.close();
        }
 catch (        IOException e) {
          LOG.error("Error while closing",e);
        }
      }
    }
  }
);
}
 

Example 34

From project BBC-News-Reader, under directory /src/com/digitallizard/bbcnewsreader/.

Source file: Eula.java

  15 
vote

/** 
 * Closes the specified stream.
 * @param stream The stream to close.
 */
private static void closeStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 35

From project bel-editor, under directory /org.openbel.editor.core/src/org/openbel/editor/core/common/.

Source file: BELUtilities.java

  15 
vote

/** 
 * Closes the  {@link Closeable resource} without throwing an exception.
 * @param resource the  {@link Closeable resource} to close
 */
public static void closeSilently(final Closeable resource){
  if (resource != null) {
    try {
      resource.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 36

From project Book-Catalogue, under directory /src/com/eleybourn/bookcatalogue/.

Source file: CropUtil.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 37

From project brix-cms, under directory /brix-rmiserver/src/main/java/org/brixcms/rmiserver/jackrabbit/.

Source file: RepositoryFactoryBean.java

  15 
vote

public static final void close(Closeable c){
  if (c != null) {
    try {
      c.close();
    }
 catch (    IOException e) {
      throw new RuntimeException("Could not close stream",e);
    }
  }
}
 

Example 38

From project bundlemaker, under directory /main/org.bundlemaker.core/src/org/bundlemaker/core/util/.

Source file: FileUtils.java

  15 
vote

/** 
 * Closes the supplied stream if it's available.
 * @param closeable the closeable. Maybe <code>null</code>.
 */
public static final void close(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException ex) {
    }
  }
}
 

Example 39

From project cascading, under directory /src/core/cascading/tuple/collect/.

Source file: SpillableTupleList.java

  15 
vote

private void closeSilent(Closeable closeable){
  try {
    closeable.close();
  }
 catch (  IOException exception) {
  }
}
 

Example 40

From project ccw, under directory /ccw.util/src/java/ccw/util/.

Source file: IOUtils.java

  15 
vote

public static void safeClose(Closeable toClose){
  if (toClose != null) {
    try {
      toClose.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 41

From project ceylon-runtime, under directory /api/src/main/java/ceylon/modules/api/compiler/.

Source file: AbstractCompilerAdapter.java

  15 
vote

/** 
 * Safe close.
 * @param closeable the closeable
 */
protected static void safeClose(final Closeable closeable){
  if (closeable != null)   try {
    closeable.close();
  }
 catch (  IOException e) {
  }
}
 

Example 42

From project clustermeister, under directory /node-common/src/main/java/com/github/nethad/clustermeister/node/common/.

Source file: ClustermeisterLauncher.java

  15 
vote

private void closeStream(Closeable in){
  if (in != null) {
    try {
      in.close();
    }
 catch (    IOException ex) {
      logger.warn("Can not close stream.",ex);
    }
  }
}
 

Example 43

From project commons-compress, under directory /src/test/java/org/apache/commons/compress/.

Source file: AbstractTestCase.java

  15 
vote

protected void closeQuietly(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException ignored) {
    }
  }
}
 

Example 44

From project Core_2, under directory /shell/src/main/java/org/jboss/forge/shell/console/jline/internal/.

Source file: TerminalLineSettings.java

  15 
vote

private static void close(final Closeable... closeables){
  for (  Closeable c : closeables) {
    try {
      c.close();
    }
 catch (    Exception e) {
    }
  }
}
 

Example 45

From project cropimage, under directory /src/com/droid4you/util/cropimage/.

Source file: Util.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 46

From project curator, under directory /curator-x-discovery/src/test/java/com/netflix/curator/x/discovery/.

Source file: TestServiceCache.java

  15 
vote

@Test public void testViaProvider() throws Exception {
  List<Closeable> closeables=Lists.newArrayList();
  TestingServer server=new TestingServer();
  closeables.add(server);
  try {
    CuratorFramework client=CuratorFrameworkFactory.newClient(server.getConnectString(),new RetryOneTime(1));
    closeables.add(client);
    client.start();
    ServiceDiscovery<String> discovery=ServiceDiscoveryBuilder.builder(String.class).basePath("/discovery").client(client).build();
    closeables.add(discovery);
    discovery.start();
    ServiceProvider<String> serviceProvider=discovery.serviceProviderBuilder().serviceName("test").build();
    closeables.add(serviceProvider);
    serviceProvider.start();
    ServiceInstance<String> instance=ServiceInstance.<String>builder().payload("thing").name("test").port(10064).build();
    discovery.registerService(instance);
    int count=0;
    ServiceInstance<String> foundInstance=null;
    while (foundInstance == null) {
      Assert.assertTrue(count++ < 5);
      foundInstance=serviceProvider.getInstance();
      Thread.sleep(1000);
    }
    Assert.assertEquals(foundInstance,instance);
  }
  finally {
    Collections.reverse(closeables);
    for (    Closeable c : closeables) {
      Closeables.closeQuietly(c);
    }
  }
}
 

Example 47

From project cytoscape-plugins, under directory /org.openbel.cytoscape.navigator/src/org/openbel/cytoscape/navigator/.

Source file: Utility.java

  15 
vote

/** 
 * Closes a  {@link Closeable} silently
 * @param closable
 */
public static void closeSilently(final Closeable closable){
  if (closable == null) {
    return;
  }
  try {
    closable.close();
  }
 catch (  IOException e) {
  }
}
 

Example 48

From project daap, under directory /src/main/java/org/ardverk/daap/io/.

Source file: IoUtils.java

  15 
vote

public static boolean close(Closeable c){
  if (c != null) {
    try {
      c.close();
      return true;
    }
 catch (    IOException ignore) {
    }
  }
  return false;
}
 

Example 49

From project danbo, under directory /src/us/donmai/danbooru/danbo/cropimage/.

Source file: Util.java

  15 
vote

public static void closeSilently(Closeable c){
  if (c == null)   return;
  try {
    c.close();
  }
 catch (  Throwable t) {
  }
}
 

Example 50

From project dcm4che, under directory /dcm4che-core/src/main/java/org/dcm4che/util/.

Source file: SafeClose.java

  15 
vote

public static void close(Closeable io){
  if (io != null)   try {
    io.close();
  }
 catch (  IOException ignore) {
  }
}
 

Example 51

From project droidparts, under directory /extra/src/org/droidparts/util/io/.

Source file: IOUtils.java

  15 
vote

public static void silentlyClose(Closeable... closeables){
  for (  Closeable cl : closeables) {
    try {
      cl.close();
    }
 catch (    Exception e) {
      L.d(e);
    }
  }
}
 

Example 52

From project Eclipse, under directory /com.mobilesorcery.sdk.core/src/com/mobilesorcery/sdk/core/.

Source file: Util.java

  15 
vote

public static void safeClose(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 53

From project ehour, under directory /eHour-common/src/main/java/net/rrm/ehour/util/.

Source file: IoUtil.java

  15 
vote

public static void close(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 54

From project empire-db, under directory /empire-db/src/main/java/org/apache/empire/xml/.

Source file: XMLConfiguration.java

  15 
vote

private void close(final Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
      log.debug(e.getMessage());
    }
  }
}
 

Example 55

From project en, under directory /src/l1j/server/server/utils/.

Source file: StreamUtil.java

  15 
vote

public static void close(Closeable... closeables){
  for (  Closeable c : closeables) {
    try {
      if (c != null) {
        c.close();
      }
    }
 catch (    IOException e) {
      _log.log(Level.SEVERE,e.getLocalizedMessage(),e);
    }
  }
}
 

Example 56

From project enterprise, under directory /server-enterprise/src/test/java/org/neo4j/server/enterprise/.

Source file: ServerTestUtils.java

  15 
vote

private static void safeClose(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}
 

Example 57

From project erjang, under directory /src/main/java/erjang/.

Source file: RuntimeInfo.java

  15 
vote

protected static void closeQuietly(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    Throwable t) {
    }
  }
}
 

Example 58

From project etherpad, under directory /infrastructure/net.appjet.common/util/.

Source file: LenientFormatter.java

  15 
vote

/** 
 * Closes the  {@code Formatter}. If the output destination is  {@link Closeable}, then the method  {@code close()} will be called on that destination.If the  {@code Formatter} has been closed, then calling the this method will have noeffect. Any method but the  {@link #ioException()} that is called after the{@code Formatter} has been closed will raise a {@code FormatterClosedException}.
 */
public void close(){
  closed=true;
  try {
    if (out instanceof Closeable) {
      ((Closeable)out).close();
    }
  }
 catch (  IOException e) {
    lastIOException=e;
  }
}
 

Example 59

From project fest-util, under directory /src/main/java/org/fest/util/.

Source file: Closeables.java

  15 
vote

private static void closeCloseable(Closeable c){
  if (c == null) {
    return;
  }
  try {
    c.close();
  }
 catch (  Throwable t) {
    logger.log(Level.WARNING,"Error ocurred while closing " + c,t);
  }
}
 

Example 60

From project fitnesse, under directory /src/fitnesse/slim/.

Source file: Jsr223Bridge.java

  15 
vote

public void close(){
  try {
    ((Closeable)getScriptEngine()).close();
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
}
 

Example 61

From project Foglyn, under directory /com.foglyn.fogbugz/src/com/foglyn/fogbugz/.

Source file: Utils.java

  15 
vote

/** 
 * Closes stream and ignores error while doing so. Don't use with output streams!
 * @param stream
 */
static void close(Closeable stream){
  if (stream == null) {
    return;
  }
  try {
    stream.close();
  }
 catch (  IOException e) {
  }
}
 

Example 62

From project gatein-common, under directory /common/src/main/java/org/gatein/common/io/.

Source file: IOTools.java

  15 
vote

/** 
 * <p>Attempt to close an  {@link Closeable} object. Null argument value is authorized and no operation will beperformed in that use case.  {@link IOException} thrown are logged using the <code>error</code> level but notpropagated.</p>
 * @param out the stream to close
 */
public static void safeClose(Closeable out){
  if (out != null) {
    try {
      out.close();
    }
 catch (    IOException e) {
      log.error("Error while closing closeable " + out,e);
    }
  }
}
 

Example 63

From project gda-common, under directory /uk.ac.gda.common/src/gda/util/.

Source file: OSCommandRunner.java

  15 
vote

private static void closeStream(Closeable stream,String name){
  try {
    stream.close();
  }
 catch (  IOException ioe) {
    logger.warn(String.format("Unable to close process %s stream",name),ioe);
  }
}
 

Example 64

From project geronimo-xbean, under directory /xbean-finder/src/test/java/org/apache/xbean/finder/util/.

Source file: IOUtil.java

  15 
vote

public static void close(Closeable closeable) throws IOException {
  if (closeable == null)   return;
  try {
    if (closeable instanceof Flushable) {
      ((Flushable)closeable).flush();
    }
  }
 catch (  IOException e) {
  }
  try {
    closeable.close();
  }
 catch (  IOException e) {
  }
}
 

Example 65

From project git-starteam, under directory /fake-starteam/src/org/ossnoize/fakestarteam/.

Source file: FileUtility.java

  15 
vote

public static void close(Closeable... list){
  for (  Closeable c : list) {
    if (null != c) {
      try {
        c.close();
      }
 catch (      IOException e) {
      }
    }
  }
}
 

Example 66

From project gmarks-android, under directory /src/main/java/org/thomnichols/android/gmarks/thirdparty/.

Source file: IOUtils.java

  15 
vote

/** 
 * Unconditionally close a <code>Closeable</code>. <p> Equivalent to  {@link Closeable#close()}, except any exceptions will be ignored. This is typically used in finally blocks. <p> Example code: <pre> Closeable closeable = null; try { closeable = new FileReader("foo.txt"); // process closeable closeable.close(); } catch (Exception e) { // error handling } finally { IOUtils.closeQuietly(closeable); } </pre>
 * @param closeable the object to close, may be null or already closed
 * @since Commons IO 2.0
 */
public static void closeQuietly(Closeable closeable){
  try {
    if (closeable != null) {
      closeable.close();
    }
  }
 catch (  IOException ioe) {
  }
}
 

Example 67

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/util/.

Source file: Resources.java

  15 
vote

public static void close(Closeable resource){
  try {
    resource.close();
  }
 catch (  IOException e) {
    logger.log(Level.WARN,e);
  }
}
 

Example 68

From project HarleyDroid, under directory /src/org/harleydroid/.

Source file: Eula.java

  15 
vote

/** 
 * Closes the specified stream.
 * @param stream The stream to close.
 */
private static void closeStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 69

From project HBase-Lattice, under directory /hbl/src/main/java/com/inadco/hbl/client/.

Source file: HblAdmin.java

  15 
vote

@PostConstruct public void init() throws IOException {
  Validate.notNull(cubeModel);
  Deque<Closeable> closeables=new ArrayDeque<Closeable>();
  try {
    InputStream cubeIs=cubeModel.getInputStream();
    closeables.addFirst(cubeIs);
    cubeModelYamlStr=IOUtil.fromStream(cubeIs,"utf-8");
    cube=YamlModelParser.parseYamlModel(cubeModelYamlStr);
  }
  finally {
    IOUtil.closeAll(closeables);
  }
}
 

Example 70

From project heritrix3, under directory /commons/src/main/java/org/archive/util/.

Source file: ArchiveUtils.java

  15 
vote

public static void closeQuietly(Object input){
  if (input == null || !(input instanceof Closeable)) {
    return;
  }
  try {
    ((Closeable)input).close();
  }
 catch (  IOException ioe) {
  }
}
 

Example 71

From project hotpotato, under directory /src/test/java/com/biasedbit/hotpotato/client/.

Source file: HttpsTest.java

  15 
vote

private static void closeQuietly(Closeable... closeables){
  if (null != closeables) {
    for (    Closeable closeable : closeables) {
      if (null != closeable) {
        try {
          closeable.close();
        }
 catch (        Exception e) {
        }
      }
    }
  }
}
 

Example 72

From project HSR-Timetable, under directory /HSRTimeTable/src/ch/scythe/hsr/api/.

Source file: TimeTableAPI.java

  15 
vote

private void safeCloseStream(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 73

From project httpbuilder, under directory /src/main/java/groovyx/net/http/.

Source file: HTTPBuilder.java

  15 
vote

/** 
 * <p>This is the default <code>response.success</code> handler.  It will be  executed if the response is not handled by a status-code-specific handler  (i.e. <code>response.'200'= {..}</code>) and no generic 'success' handler  is given (i.e. <code>response.success = {..}</code>.)  This handler simply  returns the parsed data from the response body.  In most cases you will  probably want to define a <code>response.success = {...}</code> handler  from the request closure, which will replace the response handler defined  by this method.  </p> <h4>Note for parsers that return streaming content:</h4> <p>For responses parsed as  {@link ParserRegistry#parseStream(HttpResponse) BINARY} or {@link ParserRegistry#parseText(HttpResponse) TEXT}, the  parser will return streaming content -- an <code>InputStream</code> or  <code>Reader</code>.  In these cases, this handler will buffer the the  response content before the network connection is closed.  </p> <p>In practice, a user-supplied response handler closure is  <i>designed</i> to handle streaming content so it can be read directly from  the response stream without buffering, which will be much more efficient. Therefore, it is recommended that request method variants be used which  explicitly accept a response handler closure in these cases.</p>
 * @param resp HTTP response
 * @param parsedData parsed data as resolved from this instance's {@link ParserRegistry}
 * @return the parsed data object (whatever the parser returns).
 * @throws ResponseParseException if there is an error buffering a streamingresponse.
 */
protected Object defaultSuccessHandler(HttpResponseDecorator resp,Object parsedData) throws ResponseParseException {
  try {
    if (parsedData instanceof InputStream) {
      ByteArrayOutputStream buffer=new ByteArrayOutputStream();
      DefaultGroovyMethods.leftShift(buffer,(InputStream)parsedData);
      parsedData=new ByteArrayInputStream(buffer.toByteArray());
    }
 else     if (parsedData instanceof Reader) {
      StringWriter buffer=new StringWriter();
      DefaultGroovyMethods.leftShift(buffer,(Reader)parsedData);
      parsedData=new StringReader(buffer.toString());
    }
 else     if (parsedData instanceof Closeable)     log.warn("Parsed data is streaming, but will be accessible after " + "the network connection is closed.  Use at your own risk!");
    return parsedData;
  }
 catch (  IOException ex) {
    throw new ResponseParseException(resp,ex);
  }
}
 

Example 74

From project httpClient, under directory /httpclient-cache/src/main/java/org/apache/http/impl/client/cache/.

Source file: IOUtils.java

  15 
vote

static void closeSilently(final Closeable closable){
  try {
    closable.close();
  }
 catch (  IOException ignore) {
  }
}
 

Example 75

From project huiswerk, under directory /print/zxing-1.6/javase/src/com/google/zxing/.

Source file: StringsResourceTranslator.java

  15 
vote

private static void quietClose(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException ioe) {
    }
  }
}
 

Example 76

From project ImageLoader, under directory /core/src/main/java/com/novoda/imageloader/core/bitmap/.

Source file: BitmapUtil.java

  15 
vote

private void closeSilently(Closeable c){
  try {
    if (c != null) {
      c.close();
    }
  }
 catch (  Exception e) {
  }
}
 

Example 77

From project incubator-cordova-android, under directory /framework/src/org/apache/cordova/.

Source file: FileTransfer.java

  15 
vote

private static void safeClose(Closeable stream){
  if (stream != null) {
    try {
      stream.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 78

From project interoperability-framework, under directory /toolwrapper/src/main/java/eu/impact_project/iif/tw/util/.

Source file: FileUtil.java

  15 
vote

/** 
 * @param out The closeable (Writer, Stream, etc.) to close
 */
public static void close(final Closeable out){
  if (out != null) {
    try {
      out.close();
    }
 catch (    IOException e) {
      e.printStackTrace();
    }
  }
}
 

Example 79

From project iosched_3, under directory /android/src/com/google/android/apps/iosched/util/.

Source file: ICSDiskLruCache.java

  15 
vote

/** 
 * Closes 'closeable', ignoring any checked exceptions. Does nothing if 'closeable' is null.
 */
public static void closeQuietly(Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    final RuntimeException rethrown) {
      throw rethrown;
    }
catch (    final Exception ignored) {
    }
  }
}
 

Example 80

From project jackrabbit-oak, under directory /oak-mk/src/main/java/org/apache/jackrabbit/mk/core/.

Source file: Repository.java

  15 
vote

public void shutDown() throws Exception {
  if (!initialized) {
    return;
  }
  if (blobStoreNeedsClose && bs instanceof Closeable) {
    IOUtils.closeQuietly((Closeable)bs);
  }
  if (rs instanceof Closeable) {
    IOUtils.closeQuietly((Closeable)rs);
  }
  initialized=false;
}
 

Example 81

From project jbosgi-framework, under directory /core/src/main/java/org/jboss/osgi/framework/spi/.

Source file: VirtualFileResourceLoader.java

  15 
vote

private void safeClose(final Closeable closeable){
  if (closeable != null) {
    try {
      closeable.close();
    }
 catch (    IOException e) {
    }
  }
}
 

Example 82

From project jbosgi-vfs, under directory /api/src/main/java/org/jboss/osgi/vfs/.

Source file: VFSUtils.java

  15 
vote

/** 
 * Safely close some resource without throwing an exception.  Any exception will be logged at TRACE level.
 */
public static void safeClose(Closeable c){
  try {
    if (c != null)     c.close();
  }
 catch (  Exception ex) {
    LOGGER.tracef(ex,"Failed to close resource");
  }
}
 

Example 83

From project jboss-as-maven-plugin, under directory /src/main/java/org/jboss/as/plugin/common/.

Source file: Streams.java

  15 
vote

public static void safeClose(final Closeable closeable){
  if (closeable != null)   try {
    closeable.close();
  }
 catch (  Exception e) {
  }
}
 

Example 84

From project jboss-as-quickstart, under directory /memcached-endpoint/src/main/java/org/jboss/as/quickstarts/datagrid/memcached/.

Source file: Base64.java

  15 
vote

public static void close(Closeable cl){
  if (cl == null)   return;
  try {
    cl.close();
  }
 catch (  Exception e) {
  }
}
 

Example 85

From project jboss-ejb-client, under directory /src/main/java/org/jboss/ejb/client/remoting/.

Source file: AutoConnectionCloser.java

  15 
vote

private void safeClose(Closeable closable){
  try {
    logger.debug("Closing " + closable);
    closable.close();
  }
 catch (  Throwable e) {
    logger.debug("Exception closing " + closable,e);
  }
}
 

Example 86

From project jboss-logmanager, under directory /src/main/java/org/jboss/logmanager/handlers/.

Source file: WriterHandler.java

  15 
vote

/** 
 * Safely close the resource, reporting an error if the close fails.
 * @param c the resource
 */
protected void safeClose(Closeable c){
  try {
    if (c != null)     c.close();
  }
 catch (  Exception e) {
    reportError("Error closing resource",e,ErrorManager.CLOSE_FAILURE);
  }
catch (  Throwable ignored) {
  }
}
 

Example 87

From project jboss-modules, under directory /src/main/java/org/jboss/modules/.

Source file: FileResourceLoader.java

  15 
vote

private static void safeClose(final Closeable closeable){
  if (closeable != null)   try {
    closeable.close();
  }
 catch (  IOException e) {
  }
}
 

Example 88

From project jboss-remote-naming, under directory /src/main/java/org/jboss/naming/remote/client/.

Source file: EndpointCache.java

  15 
vote

private static void safeClose(Closeable closable){
  try {
    closable.close();
  }
 catch (  Throwable t) {
    logger.debug("Failed to close endpoint ",t);
  }
}
 

Example 89

From project jboss-remoting, under directory /src/main/java/org/jboss/remoting3/spi/.

Source file: SpiUtils.java

  15 
vote

/** 
 * A close handler which closes another resource.
 * @param c the resource to close
 * @return the close handler
 */
public static CloseHandler<Object> closingCloseHandler(final Closeable c){
  return new CloseHandler<Object>(){
    public void handleClose(    final Object closed,    final IOException exception){
      IoUtils.safeClose(c);
    }
  }
;
}
 

Example 90

From project jboss-sasl, under directory /src/main/java/org/jboss/sasl/localuser/.

Source file: LocalUserClient.java

  15 
vote

private static void safeClose(Closeable c){
  if (c != null)   try {
    c.close();
  }
 catch (  Throwable ignored) {
  }
}