List of usage examples for com.amazonaws.util Base64 decode
public static byte[] decode(byte[] b64)
From source file:org.zalando.stups.fullstop.s3.S3Writer.java
License:Apache License
public void writeToS3(String accountId, String region, Date instanceBootTime, String logData, String logType, String instanceId) throws IOException { String fileName = null;// w w w . j a v a 2 s. com DateTime dateTime = new DateTime(instanceBootTime, UTC); String keyName = Paths.get(accountId, region, dateTime.toString("YYYY"), dateTime.toString("MM"), dateTime.toString("dd"), instanceId + "-" + dateTime).toString(); switch (logType) { case USER_DATA: fileName = TAUPAGE_YAML; break; case AUDIT_LOG: fileName = AUDIT_LOG_FILE_NAME + new DateTime(UTC) + LOG_GZ; break; default: logger.error("Wrong logType given: " + logType); break; } ObjectMetadata metadata = new ObjectMetadata(); byte[] decodedLogData = Base64.decode(logData); metadata.setContentLength(decodedLogData.length); InputStream stream = new ByteArrayInputStream(decodedLogData); putObjectToS3(bucketName, fileName, keyName, metadata, stream); }
From source file:smartthings.brave.sqs.AmazonSQSRule.java
License:Apache License
private static List<Span> fromBase64(String base64) { byte[] bytes = Base64.decode(base64); return SpanBytesDecoder.JSON_V2.decodeList(bytes); }
From source file:zipkin.collector.sqs.SQSSpanProcessor.java
License:Apache License
private void process(final List<Message> messages) { if (messages.size() == 0) return;//from w w w. j av a2 s. co m final List<DeleteMessageBatchRequestEntry> toDelete = new ArrayList<>(); int count = 0; for (Message message : messages) { final String deleteId = String.valueOf(count++); try { String stringBody = message.getBody(); if (stringBody.isEmpty()) continue; // allow plain-text json, but permit base64 encoded thrift or json byte[] spans = stringBody.charAt(0) == '[' ? stringBody.getBytes(UTF_8) : Base64.decode(stringBody); collector.acceptSpans(spans, DETECTING_DECODER, new Callback<Void>() { @Override public void onSuccess(Void value) { toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } @Override public void onError(Throwable t) { logger.log(Level.WARNING, "collector accept failed", t); // for cases that are not recoverable just discard the message, // otherwise ignore so processing can be retried. if (t instanceof IllegalArgumentException) { toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } } }); } catch (RuntimeException | Error e) { logger.log(Level.WARNING, "message decoding failed", e); toDelete.add(new DeleteMessageBatchRequestEntry(deleteId, message.getReceiptHandle())); } } delete(toDelete); }
From source file:zipkin.junit.aws.AmazonSQSRule.java
License:Apache License
static Stream<? extends Span> decodeSpans(Message m) { byte[] bytes = m.getBody().charAt(0) == '[' ? m.getBody().getBytes(Charset.forName("UTF-8")) : Base64.decode(m.getBody()); return SpanBytesDecoder.JSON_V2.decodeList(bytes).stream(); }