当前位置: 首页>>代码示例>>Java>>正文


Java ArrayUtils.EMPTY_BYTE_ARRAY属性代码示例

本文整理汇总了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);
        }
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:11,代码来源:ByteUtils.java

示例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;
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:12,代码来源:LLDPTest.java

示例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();
}
 
开发者ID:villeau,项目名称:pprxmtr,代码行数:62,代码来源:GifGeneratorHandler.java


注:本文中的org.apache.commons.lang3.ArrayUtils.EMPTY_BYTE_ARRAY属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。