List of usage examples for com.google.common.base Preconditions checkNotNull
public static <T> T checkNotNull(T reference)
From source file:io.github.msdk.io.nativeformats.ZipUtils.java
/** * Extracts a zip file from stream to a directory specified by destDirectory *//*from ww w. j a v a 2 s .co m*/ static void extractStreamToFolder(final @Nonnull InputStream stream, final @Nonnull File destDirectory) throws IOException { Preconditions.checkNotNull(stream); Preconditions.checkNotNull(destDirectory); ZipInputStream zipStream = new ZipInputStream(stream); // iterates over entries in the zip file ZipEntry entry; while ((entry = zipStream.getNextEntry()) != null) { File filePath = new File(destDirectory, entry.getName()); // Create the folder for this entry, if it does not exist filePath.getParentFile().mkdirs(); if (!entry.isDirectory()) { // if the entry is a file, extracts it extractFile(zipStream, filePath); } zipStream.closeEntry(); } zipStream.close(); }
From source file:io.uploader.drive.util.ThreadUtils.java
public static void shutdownExecutor(ExecutorService executor) { Preconditions.checkNotNull(executor); logger.info("Shutdown executors"); executor.shutdown();//from ww w. java 2 s . c o m try { executor.awaitTermination(2, TimeUnit.SECONDS); } catch (InterruptedException e) { logger.error("Error occurred while awaiting threads termination", e); } List<Runnable> notStarted = executor.shutdownNow(); if (!notStarted.isEmpty()) { logger.info("Unstarted tasks stopped (" + notStarted.size() + " tasks in total)"); } }
From source file:org.opendaylight.protocol.bgp.parser.spi.MultiPathSupportUtil.java
/** * Check is AFI/SAFI is supported by {@link MultiPathSupport} service. * @param constraints Peer specific constraint. * @param afiSafi Required AFI/SAFI/*from w w w. ja v a2s . com*/ * @return True if AFI/SAFI is supported. */ public static boolean isTableTypeSupported(@Nullable final PeerSpecificParserConstraint constraints, @Nonnull final BgpTableType afiSafi) { Preconditions.checkNotNull(afiSafi); if (constraints != null) { final Optional<MultiPathSupport> peerConstraint = constraints.getPeerConstraint(MultiPathSupport.class); return peerConstraint.isPresent() && peerConstraint.get().isTableTypeSupported(afiSafi); } return false; }
From source file:net.sf.lucis.core.impl.SingleSearcherProvider.java
public static SingleSearcherProvider of(final Directory directory) { Preconditions.checkNotNull(directory); return new SingleSearcherProvider() { @Override/*from w w w . jav a 2 s .c o m*/ Directory directory() { return directory; } }; }
From source file:com.facebook.buck.rules.BuildRuleParamsFactory.java
/** * @return a {@link BuildRuleParams} with no deps or visibility patterns, and a pathRelativizer * that returns the parameter it receives verbatim. */// w ww. ja v a 2 s .c o m public static BuildRuleParams createTrivialBuildRuleParams(BuildTarget buildTarget) { return new FakeBuildRuleParams(Preconditions.checkNotNull(buildTarget)); }
From source file:com.dangdang.config.service.easyzk.support.spring.ZookeeperSourceFactory.java
public static PropertySources create(ConfigNode... configNodes) { Preconditions.checkNotNull(configNodes); final MutablePropertySources sources = new MutablePropertySources(); for (ConfigNode configNode : configNodes) { sources.addLast(new ZookeeperResource(configNode)); }//from w ww. ja v a 2s .co m return sources; }
From source file:com.palantir.lock.StringLockDescriptor.java
/** Returns a {@code LockDescriptor} instance for the given lock ID. */ public static LockDescriptor of(String lockId) { Preconditions.checkNotNull(lockId); Preconditions.checkArgument(!Strings.isNullOrEmpty(lockId)); return new LockDescriptor(lockId.getBytes(Charsets.UTF_8)); }
From source file:com.turn.griffin.utils.GriffinConfig.java
public static String getProperty(String propertyName, String defaultValue) { Preconditions.checkNotNull(propertyName); if (properties == null) { init();/* w w w . j av a 2 s . com*/ } return properties.getProperty(propertyName, defaultValue); }
From source file:org.trancecode.io.Urls.java
public static InputSupplier<InputStream> asInputSupplier(final URL url) { Preconditions.checkNotNull(url); return url::openStream; }
From source file:com.jivesoftware.os.server.http.jetty.jersey.server.binding.Injectable.java
public static <T2> Injectable<T2> of(Class<T2> injectableType, T2 instance) { Preconditions.checkNotNull(instance); return new Injectable<>(injectableType, instance); }