Example usage for com.google.common.util CharBase64 encodeWebSafe

List of usage examples for com.google.common.util CharBase64 encodeWebSafe

Introduction

In this page you can find the example usage for com.google.common.util CharBase64 encodeWebSafe.

Prototype

public static String encodeWebSafe(byte[] source, boolean doPadding) 

Source Link

Document

Encodes a byte array into web safe Base64 notation.

Usage

From source file:org.waveprotocol.wave.examples.client.webclient.waveclient.common.WebClientBackend.java

public WebClientBackend(final String userId, WaveWebSocketClient websocket) {
    connectionStatus = NetworkStatusEvent.ConnectionStatus.CONNECTED;
    this.userId = new ParticipantId(userId);
    this.websocket = websocket;
    this.sequenceNumber = 0;
    this.idGenerator = new IdGeneratorImpl(this.userId.getDomain(), new IdGeneratorImpl.Seed() {
        private final String seed;

        {/*from  w ww  .  j  av  a2 s  . co m*/
            String start = userId + System.currentTimeMillis();
            char[] chars = start.toCharArray();
            byte[] bytes = new byte[chars.length];
            for (int i = 0, j = chars.length; i < j; i++) {
                bytes[i] = (byte) chars[i];
            }
            seed = CharBase64.encodeWebSafe(bytes, false);
        }

        @Override
        public String get() {
            return seed;
        }
    });
    this.uriCodec = new IdURIEncoderDecoder(new URLEncoderDecoderBasedPercentEncoderDecoder());
    ClientEvents.get().addNetworkStatusEventHandler(new NetworkStatusEventHandler() {

        @Override
        public void onNetworkStatus(final NetworkStatusEvent event) {
            LOG.info("got network status event " + event.getStatus());
            connectionStatus = event.getStatus();
            switch (event.getStatus()) {
            case CONNECTED:
                networkReconnected();
                break;
            case DISCONNECTED:
                break;
            case RECONNECTED:
                networkReconnected();
                break;
            case RECONNECTING:
                break;
            case NEVER_CONNECTED:
                break;

            }
        }
    });
}