Examples of Charset


Examples of java.nio.charset.Charset

    }
    return text;
  }

  protected String readTextFromStream(InputStream aTextStream) {
    Charset charset = getCharSet();
    int size = urlConnection.getContentLength();
    ByteArrayOutputStream bos = new ByteArrayOutputStream(size != -1 ? size : 1024);
    byte[] buffer = new byte[1024];
    int len;
    try {
      while ((len = aTextStream.read(buffer)) != -1) {
        bos.write(buffer, 0, len);
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
    String streamedText = ""; // be robust
    try {
      streamedText = bos.toString(charset.name());
    } catch (UnsupportedEncodingException e) {} // we already checked for that above
    // check Content-Type text/plain; charset=iso-8859-1
    return streamedText;
  }
View Full Code Here

Examples of java.nio.charset.Charset

   */
  protected Charset getCharSet() {
    String contentType = urlConnection.getContentType();
    // find out about the charset from the URLConnection
    Matcher m = charsetPattern.matcher(contentType);
    Charset charset = Charset.forName("iso-8859-1"); // default charset
    if (m.find()) {
      String charsetString = m.group(1);
      try {
        charset = Charset.forName(charsetString);
      } catch (IllegalCharsetNameException e) {
View Full Code Here

Examples of java.nio.charset.Charset

   */
  public static String toString(ByteBuffer buffer, String encoding) throws UnsupportedEncodingException {
    try {
      CharsetDecoder decoder = decoders.get(encoding);
      if (decoder == null) {
        Charset charset = Charset.forName(encoding);
        decoder = charset.newDecoder();
          decoders.put(encoding, decoder);
          encoders.put(encoding, charset.newEncoder());
      }
     
      return decoder.decode(buffer).toString();
     
    } catch (CharacterCodingException cce) {
View Full Code Here

Examples of java.nio.charset.Charset

 
 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
View Full Code Here

Examples of java.nio.charset.Charset

 
 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
View Full Code Here

Examples of java.nio.charset.Charset

 
 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
View Full Code Here

Examples of java.nio.charset.Charset

        // wtf? still nothing, just take system-standard
        if (charset == null) {
            charset = Charset.defaultCharset().name();
        }
       
        Charset c;
        try {
          c = Charset.forName(charset);
        } catch (IllegalCharsetNameException e) {
          c = Charset.defaultCharset();
        } catch (UnsupportedCharsetException e) {
View Full Code Here

Examples of java.nio.charset.Charset

 
 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
View Full Code Here

Examples of java.nio.charset.Charset

 
 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
View Full Code Here

Examples of java.nio.charset.Charset

        boolean cancelled = wizardDescriptor.getValue() != WizardDescriptor.FINISH_OPTION;
        if (!cancelled) {
            //General parameters:
            File file = (File) wizardDescriptor.getProperty("file");
            Character separator = (Character) wizardDescriptor.getProperty("separator");
            Charset charset = (Charset) wizardDescriptor.getProperty("charset");
            String[] columnNames = (String[]) wizardDescriptor.getProperty("columns-names");
            AttributeType[] columnTypes = (AttributeType[]) wizardDescriptor.getProperty("columns-types");

            //Nodes import parameters:
            Boolean assignNewNodeIds = (Boolean) wizardDescriptor.getProperty("assign-new-node-ids");
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.