use of java.util.Base64 in project j2objc by google.
the class Base64Test method testRoundTrip_allBytes_mime_lineLength.
/** check a range of possible line lengths */
public void testRoundTrip_allBytes_mime_lineLength() {
Decoder decoder = Base64.getMimeDecoder();
byte[] separator = new byte[] { '*' };
checkRoundTrip_allBytes(Base64.getMimeEncoder(4, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 4));
checkRoundTrip_allBytes(Base64.getMimeEncoder(8, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 8));
checkRoundTrip_allBytes(Base64.getMimeEncoder(20, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 20));
checkRoundTrip_allBytes(Base64.getMimeEncoder(100, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, 100));
checkRoundTrip_allBytes(Base64.getMimeEncoder(Integer.MAX_VALUE & ~3, separator), decoder, wrapLines("*", ALL_BYTE_VALUES_ENCODED, Integer.MAX_VALUE & ~3));
}
use of java.util.Base64 in project pulsar by yahoo.
the class ProducerHandler method onWebSocketText.
@Override
public void onWebSocketText(String message) {
ProducerMessage sendRequest;
byte[] rawPayload = null;
String requestContext = null;
try {
sendRequest = ObjectMapperFactory.getThreadLocal().readValue(message, ProducerMessage.class);
requestContext = sendRequest.context;
rawPayload = Base64.getDecoder().decode(sendRequest.payload);
} catch (IOException e) {
sendAckResponse(new ProducerAck(FailedToDeserializeFromJSON, e.getMessage(), null, null));
return;
} catch (IllegalArgumentException e) {
String msg = format("Invalid Base64 message-payload error=%s", e.getMessage());
sendAckResponse(new ProducerAck(PayloadEncodingError, msg, null, requestContext));
return;
}
MessageBuilder builder = MessageBuilder.create().setContent(rawPayload);
if (sendRequest.properties != null) {
builder.setProperties(sendRequest.properties);
}
if (sendRequest.key != null) {
builder.setKey(sendRequest.key);
}
if (sendRequest.replicationClusters != null) {
builder.setReplicationClusters(sendRequest.replicationClusters);
}
Message msg = builder.build();
producer.sendAsync(msg).thenAccept(msgId -> {
if (isConnected()) {
String messageId = Base64.getEncoder().encodeToString(msgId.toByteArray());
sendAckResponse(new ProducerAck(messageId, sendRequest.context));
}
}).exceptionally(exception -> {
sendAckResponse(new ProducerAck(UnknownError, exception.getMessage(), null, sendRequest.context));
return null;
});
}
use of java.util.Base64 in project jdk8u_jdk by JetBrains.
the class TestBase64Golden method test1.
private static void test1() throws Exception {
byte[] src = new byte[] { 46, -97, -35, -44, 127, -60, -39, -4, -112, 34, -57, 47, -14, 67, 40, 18, 90, -59, 68, 112, 23, 121, -91, 94, 35, 49, 104, 17, 30, -80, -104, -3, -53, 27, 38, -72, -47, 113, -52, 18, 5, -126 };
Encoder encoder = Base64.getMimeEncoder(49, new byte[] { 0x7e });
byte[] encoded = encoder.encode(src);
Decoder decoder = Base64.getMimeDecoder();
byte[] decoded = decoder.decode(encoded);
if (!Objects.deepEquals(src, decoded)) {
throw new RuntimeException();
}
}
use of java.util.Base64 in project jdk8u_jdk by JetBrains.
the class TestBase64 method testDecodeUnpadded.
private static void testDecodeUnpadded() throws Throwable {
byte[] srcA = new byte[] { 'Q', 'Q' };
byte[] srcAA = new byte[] { 'Q', 'Q', 'E' };
Base64.Decoder dec = Base64.getDecoder();
byte[] ret = dec.decode(srcA);
if (ret[0] != 'A')
throw new RuntimeException("Decoding unpadding input A failed");
ret = dec.decode(srcAA);
if (ret[0] != 'A' && ret[1] != 'A')
throw new RuntimeException("Decoding unpadding input AA failed");
ret = new byte[10];
if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 1 && ret[0] != 'A')
throw new RuntimeException("Decoding unpadding input A from stream failed");
if (dec.wrap(new ByteArrayInputStream(srcA)).read(ret) != 2 && ret[0] != 'A' && ret[1] != 'A')
throw new RuntimeException("Decoding unpadding input AA from stream failed");
}
use of java.util.Base64 in project fess by codelibs.
the class AdminLogAction method getLogFileItems.
public static List<Map<String, Object>> getLogFileItems() {
final SystemHelper systemHelper = ComponentUtil.getSystemHelper();
final List<Map<String, Object>> logFileItems = new ArrayList<>();
final String logFilePath = systemHelper.getLogFilePath();
if (StringUtil.isNotBlank(logFilePath)) {
final Path logDirPath = Paths.get(logFilePath);
try (Stream<Path> stream = Files.list(logDirPath)) {
stream.filter(entry -> entry.getFileName().toString().endsWith(".log")).forEach(filePath -> {
final Map<String, Object> map = new HashMap<>();
final String name = filePath.getFileName().toString();
map.put("id", Base64.getUrlEncoder().encodeToString(name.getBytes(StandardCharsets.UTF_8)));
map.put("name", name);
try {
map.put("lastModified", new Date(Files.getLastModifiedTime(filePath).toMillis()));
} catch (final IOException e) {
throw new IORuntimeException(e);
}
logFileItems.add(map);
});
} catch (final Exception e) {
throw new FessSystemException("Failed to access log files.", e);
}
}
return logFileItems;
}
Aggregations