Search in sources :

Example 16 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project bigbluebutton by bigbluebutton.

the class BlockStreamProtocolDecoder method decodeRoom.

private String decodeRoom(IoSession session, IoBuffer in) {
    int roomLength = in.get();
    //    	System.out.println("Room length = " + roomLength);
    String room = "";
    try {
        room = in.getString(roomLength, Charset.forName("UTF-8").newDecoder());
        if (session.containsAttribute(ROOM)) {
            String attRoom = (String) session.getAttribute(ROOM);
            if (!attRoom.equals(room)) {
                log.warn(room + " is not the same as room in attribute [" + attRoom + "]");
            }
        }
    } catch (CharacterCodingException e) {
        log.error(e.getMessage());
    }
    return room;
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) Point(java.awt.Point)

Example 17 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project bigbluebutton by bigbluebutton.

the class BlockStreamProtocolDecoder method tryToParsePolicyRequest.

private boolean tryToParsePolicyRequest(IoSession session, IoBuffer in, ProtocolDecoderOutput out) {
    byte[] message = new byte[POLICY_REQUEST.length];
    if (in.remaining() >= POLICY_REQUEST.length) {
        in.get(message, 0, message.length);
        if (Arrays.equals(message, POLICY_REQUEST)) {
            log.debug("Sending cross domain policy to the user");
            IoBuffer buffer = IoBuffer.allocate(8);
            buffer.setAutoExpand(true);
            try {
                buffer.putString("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>", Charset.forName("UTF-8").newEncoder());
                buffer.put((byte) 0);
            } catch (CharacterCodingException e) {
                e.printStackTrace();
                return false;
            }
            buffer.flip();
            session.write(buffer);
            return true;
        }
    }
    return false;
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 18 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project zipkin by openzipkin.

the class CassandraSpanStore method getTraceIdsByAnnotation.

ListenableFuture<Map<Long, Long>> getTraceIdsByAnnotation(String annotationKey, long endTs, long lookback, int limit) {
    long startTs = endTs - lookback;
    try {
        BoundStatement bound = CassandraUtil.bindWithName(selectTraceIdsByAnnotation, "select-trace-ids-by-annotation").setBytes("annotation", CassandraUtil.toByteBuffer(annotationKey)).setSet("bucket", buckets).setBytesUnsafe("start_ts", timestampCodec.serialize(startTs)).setBytesUnsafe("end_ts", timestampCodec.serialize(endTs)).setInt("limit_", limit);
        bound.setFetchSize(Integer.MAX_VALUE);
        return transform(session.executeAsync(bound), new Function<ResultSet, Map<Long, Long>>() {

            @Override
            public Map<Long, Long> apply(ResultSet input) {
                Map<Long, Long> traceIdsToTimestamps = new LinkedHashMap<>();
                for (Row row : input) {
                    traceIdsToTimestamps.put(row.getLong("trace_id"), timestampCodec.deserialize(row, "ts"));
                }
                return traceIdsToTimestamps;
            }
        });
    } catch (CharacterCodingException | RuntimeException ex) {
        return immediateFailedFuture(ex);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) Row(com.datastax.driver.core.Row) CharacterCodingException(java.nio.charset.CharacterCodingException) BoundStatement(com.datastax.driver.core.BoundStatement) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 19 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project sessdb by ppdai.

the class Slices method encodeString.

public static ByteBuffer encodeString(CharBuffer src, Charset charset) {
    final CharsetEncoder encoder = getEncoder(charset);
    final ByteBuffer dst = ByteBuffer.allocate((int) ((double) src.remaining() * encoder.maxBytesPerChar()));
    try {
        CoderResult cr = encoder.encode(src, dst, true);
        if (!cr.isUnderflow()) {
            cr.throwException();
        }
        cr = encoder.flush(dst);
        if (!cr.isUnderflow()) {
            cr.throwException();
        }
    } catch (CharacterCodingException x) {
        throw new IllegalStateException(x);
    }
    dst.flip();
    return dst;
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) CharsetEncoder(java.nio.charset.CharsetEncoder) ByteBuffer(java.nio.ByteBuffer) CoderResult(java.nio.charset.CoderResult)

Example 20 with CharacterCodingException

use of java.nio.charset.CharacterCodingException in project hadoop by apache.

the class Text method set.

/** Set to contain the contents of a string. 
   */
public void set(String string) {
    try {
        ByteBuffer bb = encode(string, true);
        bytes = bb.array();
        length = bb.limit();
    } catch (CharacterCodingException e) {
        throw new RuntimeException("Should not have happened ", e);
    }
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

CharacterCodingException (java.nio.charset.CharacterCodingException)196 ByteBuffer (java.nio.ByteBuffer)114 CharBuffer (java.nio.CharBuffer)48 CharsetDecoder (java.nio.charset.CharsetDecoder)44 IOException (java.io.IOException)34 CharsetEncoder (java.nio.charset.CharsetEncoder)31 CoderResult (java.nio.charset.CoderResult)30 Charset (java.nio.charset.Charset)27 InputStream (java.io.InputStream)9 Date (java.util.Date)9 UnmappableCharacterException (java.nio.charset.UnmappableCharacterException)8 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)8 ByteArrayInputStream (java.io.ByteArrayInputStream)6 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)6 Path (java.nio.file.Path)6 ParseException (java.text.ParseException)6 Test (org.junit.Test)6 CoreException (org.eclipse.core.runtime.CoreException)5 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 OutputStream (java.io.OutputStream)4