Java Code Examples for java.io.Closeable#close()

The following examples show how to use java.io.Closeable#close() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HBaseConnectionPoolTest.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetConnectionHandleNoArgPrefersEmptySourceTarget() throws IOException {
  HBaseConnectionHandle connectionHandle = hBaseConnectionPool.getConnectionHandle();
  HBaseConnectionWrapper connection = connectionHandle.getConnection();
  List<Closeable> toClose = new ArrayList<>();
  toClose.add( connectionHandle );
  for ( int i = 0; i < 100; i++ ) {
    toClose.add( hBaseConnectionPool.getConnectionHandle( "source" ) );
  }
  for ( int i = 0; i < 100; i++ ) {
    toClose.add( hBaseConnectionPool.getConnectionHandle( "target", mock( Properties.class ) ) );
  }
  for ( Closeable closeable : toClose ) {
    closeable.close();
  }
  assertEquals( connection, hBaseConnectionPool.getConnectionHandle().getConnection() );
}
 
Example 2
Source File: IOUtils.java    From mvn-golang with Apache License 2.0 5 votes vote down vote up
/**
 * Close a closeable object quietly, added because such method in APACHE-IO
 * has been deprecated
 *
 * @param closeable object to be closed
 */
public static void closeSilently(@Nullable final Closeable closeable) {
  try {
    if (closeable != null) {
      closeable.close();
    }
  } catch (final IOException ignoring) {
  }
}
 
Example 3
Source File: PlatformDetector.java    From protoc-jar with Apache License 2.0 5 votes vote down vote up
private static void closeQuietly(Closeable obj) {
    try {
        if (obj != null) {
            obj.close();
        }
    } catch (IOException ignored) {
        // Ignore.
    }
}
 
Example 4
Source File: CommandExecutor.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected static void closeStream ( final Closeable stream )
{
    if ( stream == null )
    {
        return;
    }
    try
    {
        stream.close ();
    }
    catch ( final IOException e )
    {
        logger.warn ( "Failed to close stream", e );
    }
}
 
Example 5
Source File: CommonResources.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Close the given closeable silently.
 * @param c the closeable
 */
void close0(Closeable c) {
	try {
		if (c != null) {
			c.close();
		}
	} catch (IOException ex) {
		// Ignored
	}
}
 
Example 6
Source File: CheckstyleExecutor.java    From sonar-checkstyle with GNU Lesser General Public License v3.0 5 votes vote down vote up
@VisibleForTesting
static void close(Closeable closeable) {
    try {
        closeable.close();
    }
    catch (IOException ex) {
        throw new IllegalStateException("failed to close object", ex);
    }
}
 
Example 7
Source File: IOUtils.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
public static void closeQuietly(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException ignore) {
            // skip
        }
    }
}
 
Example 8
Source File: BitmapUtils.java    From FastAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 关闭 IO
 *
 * @param closeables closeables
 */
public static void closeIO(Closeable... closeables) {
    if (closeables == null) return;
    for (Closeable closeable : closeables) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 9
Source File: InternalSerialUtils.java    From Serial with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the passed closeable without raising exceptions.
 *
 * @param closeable the object to close or null
 */
public static void closeSilently(@Nullable Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException ignore) {
        }
    }
}
 
Example 10
Source File: CropUtil.java    From XERUNG with Apache License 2.0 5 votes vote down vote up
public static void closeSilently(@Nullable Closeable c) {
    if (c == null) return;
    try {
        c.close();
    } catch (Throwable t) {
        // Do nothing
    }
}
 
Example 11
Source File: BitmapUtils.java    From giffun with Apache License 2.0 5 votes vote down vote up
/**
 * Close the given closeable object (Stream) in a safe way: check if it is null and catch-log
 * exception thrown.
 *
 * @param closeable the closable object to close
 */
private static void closeSafe(Closeable closeable) {
  if (closeable != null) {
    try {
      closeable.close();
    } catch (IOException ignored) {
    }
  }
}
 
Example 12
Source File: IOHelper.java    From fabric8-forge with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the given resource if it is available, logging any closing exceptions to the given log.
 *
 * @param closeable the object to close
 */
public static void close(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException e) {
            // ignore
        }
    }
}
 
Example 13
Source File: UploadFileUtil.java    From BreakPointUploadUtil with Apache License 2.0 5 votes vote down vote up
public static void close(Closeable stream) {
    try {
        if (stream != null)
            stream.close();
    } catch (IOException e) {
    }
}
 
Example 14
Source File: Utility.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
public static void closeSilently(Closeable closeable) {
    if (closeable != null) {
        try {
            closeable.close();
        } catch (IOException ignored) {

        }
    }
}
 
Example 15
Source File: CloseUtils.java    From AndroidUtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * Close the io stream quietly.
 *
 * @param closeables The closeables.
 */
public static void closeIOQuietly(final Closeable... closeables) {
    if (closeables == null) return;
    for (Closeable closeable : closeables) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException ignored) {
            }
        }
    }
}
 
Example 16
Source File: ServerImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
public void stop() {
    if (stopped) {
        return;
    }

    LOG.fine("Server is stopping.");

    for (Closeable c : endpoint.getCleanupHooks()) {
        try {
            c.close();
        } catch (IOException e) {
            //ignore
        }
    }
    if (slcMgr != null) {
        slcMgr.stopServer(this);
    }

    MessageObserver mo = getDestination().getMessageObserver();
    if (mo instanceof MultipleEndpointObserver) {
        ((MultipleEndpointObserver)mo).getEndpoints().remove(endpoint);
        if (((MultipleEndpointObserver)mo).getEndpoints().isEmpty()) {
            getDestination().setMessageObserver(null);
        }
    } else {
        getDestination().setMessageObserver(null);
    }
    stopped = true;
}
 
Example 17
Source File: DirectHTableWriter.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private void tryClosingResourceSilently(Closeable res) {
    if (res != null) {
        try {
            res.close();
        } catch (IOException e) {
            LOGGER.error("Closing resource: " + res + " failed with error: ", e);
        }
    }
}
 
Example 18
Source File: NistMirrorTask.java    From dependency-track with Apache License 2.0 5 votes vote down vote up
/**
 * Closes a closable object.
 * @param object the object to close
 */
private void close(final Closeable object) {
    if (object != null) {
        try {
            object.close();
        } catch (IOException e) {
            LOGGER.warn("Error closing stream", e);
        }
    }
}
 
Example 19
Source File: GestureUtils.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the specified stream.
 *
 * @param stream The stream to close.
 */
static void closeStream(Closeable stream) {
    if (stream != null) {
        try {
            stream.close();
        } catch (IOException e) {
            Log.e(LOG_TAG, "Could not close stream", e);
        }
    }
}
 
Example 20
Source File: DiskLruCache.java    From WelikeAndroid with Apache License 2.0 5 votes vote down vote up
/**
 * 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 (RuntimeException rethrown) {
            throw rethrown;
        } catch (Exception ignored) {
        }
    }
}