Examples of averageBytesPerChar()


Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        final Charset charSet = charsetForName(encoding);
        final CharsetEncoder encoder = charSet.newEncoder().onMalformedInput(
            CodingErrorAction.REPLACE).onUnmappableCharacter(
            CodingErrorAction.REPLACE);
        final float maxBytesPerChar     = encoder.maxBytesPerChar();
        final float averageBytesPerChar = encoder.averageBytesPerChar();
        final boolean fixedWidthCharset =
            (maxBytesPerChar == Math.round(maxBytesPerChar))
            && (maxBytesPerChar == averageBytesPerChar);

        //
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

   * @see CharsetEncoder#encode(java.nio.CharBuffer)
   */
  private static ByteBuffer encode(final CharBuffer in, final Charset charset) {
    final CharsetEncoder encoder = charset.newEncoder(); // encoders are not thread-safe, create a new one on every call

    int n = (int)(in.remaining() * encoder.averageBytesPerChar());
    ByteBuffer out = BufferUtils.createByteBuffer(n);

    if ( n == 0 && in.remaining() == 0 )
      return out;

View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        CharBuffer buffer = CharBuffer.wrap(sequence);
        CharsetEncoder encoder = getEncoder();

        int n = 0;
        if (buffer.remaining() > 0) {
            n = (int) (buffer.remaining() * encoder.averageBytesPerChar());
            if (n == 0) {
                n = (int) (buffer.remaining() * encoder.maxBytesPerChar());
            }
        }
        ByteBuffer result = ByteBuffer.allocate(n); // judge result length
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        final Charset charSet = charsetForName(encoding);
        final CharsetEncoder encoder = charSet.newEncoder().onMalformedInput(
            CodingErrorAction.REPLACE).onUnmappableCharacter(
            CodingErrorAction.REPLACE);
        final float maxBytesPerChar     = encoder.maxBytesPerChar();
        final float averageBytesPerChar = encoder.averageBytesPerChar();
        final boolean fixedWidthCharset =
            (maxBytesPerChar == Math.round(maxBytesPerChar))
            && (maxBytesPerChar == averageBytesPerChar);

        //
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        .onUnmappableCharacter(CodingErrorAction.IGNORE));

    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);

    /*
     * ------------------------ Exceptional cases -------------------------
     */
 
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

  public void testCharsetEncoderCharsetfloatfloatbyteArray() {
    byte[] ba = getLegalByteArray();
    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES, ba);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0.0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);
    assertSame(ba, ec.replacement());

    /*
     * ------------------------ Exceptional cases -------------------------
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        {
            String data = stringArg(args, 0);
            Charset charset = resolveEncoding(args, 1);
            CharsetEncoder encoder = Charsets.get().getEncoder(charset);

            if (encoder.averageBytesPerChar() == encoder.maxBytesPerChar()) {
                // Optimize for ASCII
                return Math.ceil(encoder.maxBytesPerChar() * data.length());
            }

            // Encode into a small temporary buffer to make counting easiest.
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        .onUnmappableCharacter(CodingErrorAction.IGNORE));

    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);

    /*
     * ------------------------ Exceptional cases -------------------------
     */
 
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

  public void testCharsetEncoderCharsetfloatfloatbyteArray() {
    byte[] ba = getLegalByteArray();
    // normal case
    CharsetEncoder ec = new MockCharsetEncoder(cs, 1, MAX_BYTES, ba);
    assertSame(ec.charset(), cs);
    assertEquals(1.0, ec.averageBytesPerChar(), 0.0);
    assertTrue(ec.maxBytesPerChar() == MAX_BYTES);
    assertSame(ba, ec.replacement());

    /*
     * ------------------------ Exceptional cases -------------------------
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

    public ByteBuffer encode(CharBuffer buffer) {
        CharsetEncoder encoder = getEncoder();

        int n = 0;
        if (buffer.remaining() > 0) {
            n = (int) (buffer.remaining() * encoder.averageBytesPerChar());
            if (n == 0)
                n = (int) (buffer.remaining() * encoder.maxBytesPerChar());
        }
        ByteBuffer result = ByteBuffer.allocate(n);
        if (n == 0)
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.