本文整理匯總了Java中com.google.common.io.ByteSource.isEmpty方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteSource.isEmpty方法的具體用法?Java ByteSource.isEmpty怎麽用?Java ByteSource.isEmpty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.common.io.ByteSource
的用法示例。
在下文中一共展示了ByteSource.isEmpty方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: consumeByteSourceOrNull
import com.google.common.io.ByteSource; //導入方法依賴的package包/類
/**
* Read the contents of the source into a byte array.
* @param source the byte array source
* @return the byte[] read from the source or null
*/
private byte[] consumeByteSourceOrNull(final ByteSource source) {
try {
if (source == null || source.isEmpty()) {
return null;
}
return source.read();
} catch (final IOException e) {
logger.warn("Could not consume the byte array source", e);
return null;
}
}
示例2: doExecute
import com.google.common.io.ByteSource; //導入方法依賴的package包/類
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final String username = requestContext.getRequestParameters().get("username");
if (StringUtils.isBlank(username)) {
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, StringUtils.EMPTY);
}
final ByteSource graphics = repository.getGraphics(username);
if (graphics == null || graphics.isEmpty()) {
throw new UnauthorizedServiceException(UnauthorizedServiceException.CODE_UNAUTHZ_SERVICE, StringUtils.EMPTY);
}
final byte[] image = EncodingUtils.encodeBase64ToByteArray(graphics.read());
requestContext.getFlowScope().put("guaUsername", username);
requestContext.getFlowScope().put("guaUserImage", new String(image, StandardCharsets.UTF_8));
return success();
}
示例3: consumeByteSourceOrNull
import com.google.common.io.ByteSource; //導入方法依賴的package包/類
/**
* Read the contents of the source into a byte array.
* @param source the byte array source
* @return the byte[] read from the source or null
*/
private static byte[] consumeByteSourceOrNull(final ByteSource source) {
try {
if (source == null || source.isEmpty()) {
return null;
}
return source.read();
} catch (final IOException e) {
LOGGER.warn("Could not consume the byte array source", e);
return null;
}
}