Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder


        MessageDigest digest = Util.getMD5Digest();

        // Compute digest of method names and signatures, in order.
        // Also, compute method hashes.
        CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
        for (Method method : methodList) {
            work(digest, method.getName(), encoder);
            work(digest, method.getSignature(), encoder);

            MethodHash methodHash = new MethodHash().computeHash(method);
View Full Code Here


    public void writeUTF(String string) throws JMSException
    {
        checkWritable();
        try
        {
            CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
            java.nio.ByteBuffer encodedString = encoder.encode(CharBuffer.wrap(string));
           
            _data.putShort((short)encodedString.limit());
            _data.put(encodedString);
            _changedData = true;
            //_data.putString(string, Charset.forName("UTF-8").newEncoder());
View Full Code Here

    // later on during sorting and iteration.
    //
    entries = list;
    int i, o;

    final CharsetEncoder nameEncoder = state.nameEncoder;
    for (i = 0, o = 0; i < entries.length; i++) {
      final Entry e = entries[i];
      if (e == null)
        continue;
      final String name = e.getName();
View Full Code Here

  public canEncode() {
  }

  public void test(TestHarness harness) {
    // Regression test for PR 29178.
    CharsetEncoder enc = Charset.forName("US-ASCII").newEncoder();
    harness.check(!enc.canEncode('\u00e4'));
  }
View Full Code Here

    protected final void setEncoding(final String encoding)
    throws UnsupportedEncodingException {

        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

   * instead of {@link ByteBuffer#allocate(int)}.
   *
   * @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;

    encoder.reset();
    while ( true ) {
      CoderResult cr = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
      if ( cr.isUnderflow() )
        cr = encoder.flush(out);

      if ( cr.isUnderflow() )
        break;

      if ( cr.isOverflow() ) {
View Full Code Here

      return (Session) sessions.get(new Integer(sessionID));
  }
    }

    private static ByteBuffer getUTF8BufferFromString(String s) {
  CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
  try {
      return encoder.encode(CharBuffer.wrap(s));
  } catch (CharacterCodingException e) {
      return null;
  }
    }
View Full Code Here

  @Test
  public void strings() {
    String ss = "仰望着天空寻找一位失去的故友悄无声息的离开了也带上了命运";
    Charset UTF8 = Charset.forName("UTF-8");
    CharsetEncoder enc = UTF8.newEncoder();
    // enc.

  }
View Full Code Here

        Assert.assertEquals( 4, buf.limit() );
    }
   
    public void testPutString() throws Exception
    {
        CharsetEncoder encoder;
        ByteBuffer buf = ByteBuffer.allocate( 16 );
        encoder = Charset.forName( "ISO-8859-1" ).newEncoder();
       
        buf.putString( "ABC", encoder );
        Assert.assertEquals( 3, buf.position() );
View Full Code Here

        String message= NLSUtility.format(TextEditorMessages.DocumentProvider_error_illegal_encoding_message_arg, encoding);
        IStatus s= new Status(IStatus.ERROR, EditorsUI.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
      }

      CharsetEncoder encoder= charset.newEncoder();
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      InputStream stream;

      try {
        byte[] bytes;
        ByteBuffer byteBuffer= encoder.encode(CharBuffer.wrap(document.get()));
        if (byteBuffer.hasArray())
          bytes= byteBuffer.array();
        else {
          bytes= new byte[byteBuffer.limit()];
          byteBuffer.get(bytes);
View Full Code Here

TOP

Related Classes of java.nio.charset.CharsetEncoder

Copyright © 2018 www.massapicom. 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.