Search in sources :

Example 26 with Base64

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));
}
Also used : Decoder(java.util.Base64.Decoder)

Example 27 with Base64

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;
    });
}
Also used : ProducerMessage(com.yahoo.pulsar.websocket.data.ProducerMessage) WebSocketError(com.yahoo.pulsar.websocket.WebSocketError) Logger(org.slf4j.Logger) Producer(com.yahoo.pulsar.client.api.Producer) LoggerFactory(org.slf4j.LoggerFactory) MessageRoutingMode(com.yahoo.pulsar.client.api.ProducerConfiguration.MessageRoutingMode) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ProducerConfiguration(com.yahoo.pulsar.client.api.ProducerConfiguration) String.format(java.lang.String.format) ObjectMapperFactory(com.yahoo.pulsar.common.util.ObjectMapperFactory) TimeUnit(java.util.concurrent.TimeUnit) MessageBuilder(com.yahoo.pulsar.client.api.MessageBuilder) Base64(java.util.Base64) HttpServletRequest(javax.servlet.http.HttpServletRequest) CompressionType(com.yahoo.pulsar.client.api.CompressionType) Session(org.eclipse.jetty.websocket.api.Session) Message(com.yahoo.pulsar.client.api.Message) ProducerAck(com.yahoo.pulsar.websocket.data.ProducerAck) DestinationName(com.yahoo.pulsar.common.naming.DestinationName) MessageBuilder(com.yahoo.pulsar.client.api.MessageBuilder) ProducerMessage(com.yahoo.pulsar.websocket.data.ProducerMessage) Message(com.yahoo.pulsar.client.api.Message) ProducerMessage(com.yahoo.pulsar.websocket.data.ProducerMessage) IOException(java.io.IOException) ProducerAck(com.yahoo.pulsar.websocket.data.ProducerAck)

Example 28 with Base64

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();
    }
}
Also used : Encoder(java.util.Base64.Encoder) BASE64Encoder(sun.misc.BASE64Encoder) Decoder(java.util.Base64.Decoder) BASE64Decoder(sun.misc.BASE64Decoder)

Example 29 with Base64

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");
}
Also used : Base64(java.util.Base64) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 30 with Base64

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;
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) FessSystemException(org.codelibs.fess.exception.FessSystemException) Date(java.util.Date) StringUtil(org.codelibs.core.lang.StringUtil) IOException(java.io.IOException) HashMap(java.util.HashMap) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) ActionRuntime(org.lastaflute.web.ruts.process.ActionRuntime) StandardCharsets(java.nio.charset.StandardCharsets) RenderDataUtil(org.codelibs.fess.util.RenderDataUtil) ArrayList(java.util.ArrayList) ActionResponse(org.lastaflute.web.response.ActionResponse) Base64(java.util.Base64) List(java.util.List) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) ComponentUtil(org.codelibs.fess.util.ComponentUtil) FessAdminAction(org.codelibs.fess.app.web.base.FessAdminAction) SystemHelper(org.codelibs.fess.helper.SystemHelper) Map(java.util.Map) Execute(org.lastaflute.web.Execute) HtmlResponse(org.lastaflute.web.response.HtmlResponse) Path(java.nio.file.Path) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Date(java.util.Date) FessSystemException(org.codelibs.fess.exception.FessSystemException) IOException(java.io.IOException) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) FessSystemException(org.codelibs.fess.exception.FessSystemException) SystemHelper(org.codelibs.fess.helper.SystemHelper) IORuntimeException(org.lastaflute.di.exception.IORuntimeException) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Decoder (java.util.Base64.Decoder)16 Base64 (java.util.Base64)11 Encoder (java.util.Base64.Encoder)10 ByteBuffer (java.nio.ByteBuffer)5 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 Row (com.datastax.driver.core.Row)1 ConsumerContextConfig (com.dell.cpsd.service.common.client.context.ConsumerContextConfig)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 Unauthorized401Exception (com.nike.riposte.server.error.exception.Unauthorized401Exception)1 CompressionType (com.yahoo.pulsar.client.api.CompressionType)1 Message (com.yahoo.pulsar.client.api.Message)1 MessageBuilder (com.yahoo.pulsar.client.api.MessageBuilder)1 Producer (com.yahoo.pulsar.client.api.Producer)1 ProducerConfiguration (com.yahoo.pulsar.client.api.ProducerConfiguration)1