Package java.nio.charset

Examples of java.nio.charset.UnsupportedCharsetException


        }

        try {
            return new String(data, charsetName);
        } catch (UnsupportedEncodingException e) {
            throw new UnsupportedCharsetException(charsetName);
        }
    }
View Full Code Here


        }
        try {
            this.content = string.getBytes(charset.name());
        } catch (UnsupportedEncodingException ex) {
            // should never happen
            throw new UnsupportedCharsetException(charset.name());
        }
        if (contentType != null) {
            setContentType(contentType.toString());
        }
    }
View Full Code Here

* Test class UnsupportedCharsetException.
*/
public class UnsupportedCharsetExceptionTest extends TestCase {

  public void testConstructor() {
    UnsupportedCharsetException ex = new UnsupportedCharsetException(
        "impossible");
    assertTrue(ex instanceof IllegalArgumentException);
    assertNull(ex.getCause());
    assertEquals(ex.getCharsetName(), "impossible");
    assertTrue(ex.getMessage().indexOf("impossible") != -1);

    ex = new UnsupportedCharsetException("ascii");
    assertNull(ex.getCause());
    assertEquals(ex.getCharsetName(), "ascii");
    assertTrue(ex.getMessage().indexOf("ascii") != -1);

    ex = new UnsupportedCharsetException("");
    assertNull(ex.getCause());
    assertEquals(ex.getCharsetName(), "");
    ex.getMessage();

    ex = new UnsupportedCharsetException(null);
    assertNull(ex.getCause());
    assertNull(ex.getCharsetName());
    assertTrue(ex.getMessage().indexOf("null") != -1);
  }
View Full Code Here

    /**
     * @tests serialization/deserialization compatibility.
     */
    public void testSerializationSelf() throws Exception {

        SerializationTest.verifySelf(new UnsupportedCharsetException(
                "charsetName"), COMPARATOR);
    }
View Full Code Here

    /**
     * @tests serialization/deserialization compatibility with RI.
     */
    public void testSerializationCompatibility() throws Exception {

        SerializationTest.verifyGolden(this, new UnsupportedCharsetException(
                "charsetName"), COMPARATOR);
    }
View Full Code Here

        final String csname = charset != null ? charset.name() : Consts.ASCII.name();
        try {
            this.content = text.getBytes(csname);
        } catch (final UnsupportedEncodingException ex) {
            // Should never happen
            throw new UnsupportedCharsetException(csname);
        }
    }
View Full Code Here

        }
        try {
            this.content = string.getBytes(charset.name());
        } catch (UnsupportedEncodingException ex) {
            // should never happen
            throw new UnsupportedCharsetException(charset.name());
        }
        if (contentType != null) {
            setContentType(contentType.toString());
        }
    }
View Full Code Here

        }
        try {
            this.b = s.getBytes(charset.name());
        } catch (UnsupportedEncodingException ex) {
            // should never happen
            throw new UnsupportedCharsetException(charset.name());
        }
        this.buf = ByteBuffer.wrap(this.b);
        this.content = b;
        this.buffer = this.buf;
        if (contentType != null) {
View Full Code Here

       
        Charset charset = charsetAliasMap.get(charsetLowerCase);
        if (charset == null) {
            if (areCharsetsPreloaded) {
                // if all charsets are preloaded - throw Exception right away
                throw new UnsupportedCharsetException(charsetName);
            }
           
            final Charset newCharset = Charset.forName(charsetLowerCase);
            final Charset prevCharset =
                    charsetAliasMap.putIfAbsent(charsetLowerCase, newCharset);
View Full Code Here

       
        String charset = (String) properties.get("charset");

        // Make sure we have a supported charset
        if (!Charset.isSupported(charset)) {
            throw new UnsupportedCharsetException(charset);
        }
       
        // Now we parse the data
        if (isBase64) {
            _data = Base64.decode(data);
View Full Code Here

TOP

Related Classes of java.nio.charset.UnsupportedCharsetException

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.