當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。