本文整理汇总了Java中org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY属性的典型用法代码示例。如果您正苦于以下问题:Java ArrayUtils.EMPTY_BYTE_ARRAY属性的具体用法?Java ArrayUtils.EMPTY_BYTE_ARRAY怎么用?Java ArrayUtils.EMPTY_BYTE_ARRAY使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.apache.commons.lang3.ArrayUtils
的用法示例。
在下文中一共展示了ArrayUtils.EMPTY_BYTE_ARRAY属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toBytes
public static final byte[] toBytes(String text) {
if(StringUtils.isEmpty(text)) {
return ArrayUtils.EMPTY_BYTE_ARRAY;
} else {
try {
return text.getBytes("utf-8");
} catch (UnsupportedEncodingException var2) {
throw new RuntimeException(var2);
}
}
}
示例2: awaitedBytes
private static byte[] awaitedBytes(final byte typeTLV, final short length, final byte[] value, final byte[] bytesBeforeValue) {
byte[] awaited = ArrayUtils.EMPTY_BYTE_ARRAY;
// 0 - the less meaning byte (right), 1 most meaning byte (left)
byte lengthByte0 = (byte) length;
byte lengthByte1 = (byte) (length >> 8);
awaited = ArrayUtils.addAll(awaited, (byte) (typeTLV | lengthByte1), lengthByte0);
awaited = ArrayUtils.addAll(awaited, bytesBeforeValue);
awaited = ArrayUtils.addAll(awaited, value);
return awaited;
}
示例3: handleRequest
@Override
public ApiGatewayResponse handleRequest(SNSEvent input, Context context) {
LOG.info("Loading Gif Generator Java Lambda handler.");
ObjectMapper mapper = new ObjectMapper();
if (CollectionUtils.isNotEmpty(input.getRecords())) {
try {
JsonNode json = mapper.readTree(input.getRecords().get(0).getSNS().getMessage());
byte[] gif = ArrayUtils.EMPTY_BYTE_ARRAY;
if (json.has("emojiUrl")) {
HttpClient client = HttpClientBuilder.create().build();
String emojiUrl = json.get("emojiUrl").asText();
HttpGet getImageRequest = new HttpGet(emojiUrl);
HttpResponse getImageResponse = client.execute(getImageRequest);
int getImageStatus = getImageResponse.getStatusLine().getStatusCode();
LOG.info("Get image status: {}.", getImageStatus);
if (StringUtils.contains(getImageResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue(), "image")) {
byte[] imageFile = IOUtils.toByteArray(getImageResponse.getEntity().getContent());
gif = GifGenerator.generateGif(imageFile);
} else {
LOG.error("Given image URL did not return an image according to mime type!");
}
}
if (ArrayUtils.isNotEmpty(gif)) {
LOG.info("Gif created successfully, storing in S3.");
String emoji = json.get("text").asText();
String emojiName = StringUtils.removeEnd(StringUtils.removeStart(StringUtils.strip(emoji), ":"), ":");
emojiName = emojiName.replaceAll("ä", "a").replaceAll("ö", "o").replaceAll("å", "o");
InputStream is = new ByteArrayInputStream(gif);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(gif.length);
metadata.setContentType("image/gif");
if (UrlValidator.getInstance().isValid(emojiName)) {
emojiName = CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('0', '9'))
.retainFrom(StringUtils.substringAfterLast(emojiName, "/"));
}
String filenamePrefix = emojiName + "_approximated_";
if (!S3.fileExistsInBucket(filenamePrefix)) {
S3.storeFileInBucket(filenamePrefix + System.currentTimeMillis() + ".gif", is, metadata);
}
LOG.info("Image stored in S3, publishing to topic s3-file-ready");
SNS.publish("s3-file-ready", mapper.writeValueAsString(json)).get();
} else {
LOG.error("Gif generator returned an empty byte array, sending error response");
SNS.publish("gif-generator-error", mapper.writeValueAsString(json)).get();
}
} catch (IOException | InterruptedException | ExecutionException e) {
LOG.error("Exception occured when creating GIF.", e);
}
}
Response responseBody = new Response("pprxmtr-gif-generator called.", new HashMap<>());
return ApiGatewayResponse.builder().setStatusCode(200).setObjectBody(responseBody).build();
}