Search in sources :

Example 41 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project j2objc by google.

the class StreamHandler method initializeWriter.

// initialize the writer
private void initializeWriter() {
    this.writerNotInitialized = false;
    if (getEncoding() == null) {
        this.writer = new OutputStreamWriter(this.os);
    } else {
        try {
            this.writer = new OutputStreamWriter(this.os, getEncoding());
        } catch (UnsupportedEncodingException e) {
        /*
                 * Should not happen because it's checked in
                 * super.initProperties().
                 */
        }
    }
    write(getFormatter().getHead(this));
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter)

Example 42 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project j2objc by google.

the class GenerationTest method getComGoogleDevtoolsJ2objcPath.

protected static List<String> getComGoogleDevtoolsJ2objcPath() {
    ClassLoader loader = GenerationTest.class.getClassLoader();
    List<String> classpath = Lists.newArrayList();
    if (loader instanceof URLClassLoader) {
        URL[] urls = ((URLClassLoader) GenerationTest.class.getClassLoader()).getURLs();
        String encoding = System.getProperty("file.encoding");
        for (int i = 0; i < urls.length; i++) {
            try {
                classpath.add(URLDecoder.decode(urls[i].getFile(), encoding));
            } catch (UnsupportedEncodingException e) {
                throw new AssertionError("System doesn't have the default encoding");
            }
        }
    }
    return classpath;
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) URL(java.net.URL)

Example 43 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project j2objc by google.

the class ToStream method setOutputStreamInternal.

private void setOutputStreamInternal(OutputStream output, boolean setByUser) {
    m_outputStream = output;
    String encoding = getOutputProperty(OutputKeys.ENCODING);
    if (Encodings.DEFAULT_MIME_ENCODING.equalsIgnoreCase(encoding)) {
        // We wrap the OutputStream with a writer, but
        // not one set by the user
        setWriterInternal(new WriterToUTF8Buffered(output), false);
    } else if ("WINDOWS-1250".equals(encoding) || "US-ASCII".equals(encoding) || "ASCII".equals(encoding)) {
        setWriterInternal(new WriterToASCI(output), false);
    } else if (encoding != null) {
        Writer osw = null;
        try {
            osw = Encodings.getWriter(output, encoding);
        } catch (UnsupportedEncodingException uee) {
            osw = null;
        }
        if (osw == null) {
            System.out.println("Warning: encoding \"" + encoding + "\" not supported" + ", using " + Encodings.DEFAULT_MIME_ENCODING);
            encoding = Encodings.DEFAULT_MIME_ENCODING;
            setEncoding(encoding);
            try {
                osw = Encodings.getWriter(output, encoding);
            } catch (UnsupportedEncodingException e) {
                // We can't really get here, UTF-8 is always supported
                // This try-catch exists to make the compiler happy
                e.printStackTrace();
            }
        }
        setWriterInternal(osw, false);
    } else {
        // don't have any encoding, but we have an OutputStream
        Writer osw = new OutputStreamWriter(output);
        setWriterInternal(osw, false);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Example 44 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project j2objc by google.

the class Encodings method getWriter.

/**
     * Returns a writer for the specified encoding based on
     * an output stream.
     * <p>
     * This is not a public API.
     * @param output The output stream
     * @param encoding The encoding MIME name, not a Java name for the encoding.
     * @return A suitable writer
     * @throws UnsupportedEncodingException There is no convertor
     *  to support this encoding
     * @xsl.usage internal
     */
static Writer getWriter(OutputStream output, String encoding) throws UnsupportedEncodingException {
    for (int i = 0; i < _encodings.length; ++i) {
        if (_encodings[i].name.equalsIgnoreCase(encoding)) {
            try {
                String javaName = _encodings[i].javaName;
                OutputStreamWriter osw = new OutputStreamWriter(output, javaName);
                return osw;
            } catch (// java 1.1.8
            java.lang.IllegalArgumentException iae) {
            // keep trying
            } catch (UnsupportedEncodingException usee) {
            // keep trying
            }
        }
    }
    try {
        return new OutputStreamWriter(output, encoding);
    } catch (// java 1.1.8
    java.lang.IllegalArgumentException iae) {
        throw new UnsupportedEncodingException(encoding);
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) OutputStreamWriter(java.io.OutputStreamWriter)

Example 45 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project j2objc by google.

the class FormatterTest method test_ConstructorLjava_lang_StringLjava_lang_StringLjava_util_Locale.

/**
     * java.util.Formatter#Formatter(String, String, Locale)
     */
public void test_ConstructorLjava_lang_StringLjava_lang_StringLjava_util_Locale() throws IOException {
    Formatter f = null;
    try {
        f = new Formatter((String) null, Charset.defaultCharset().name(), Locale.KOREA);
        fail("should throw NullPointerException");
    } catch (NullPointerException e1) {
    // expected
    }
    try {
        f = new Formatter(notExist.getPath(), null, Locale.KOREA);
        fail("should throw NullPointerException");
    } catch (NullPointerException e2) {
    // expected
    }
    f = new Formatter(notExist.getPath(), Charset.defaultCharset().name(), null);
    assertNotNull(f);
    f.close();
    f = new Formatter(notExist.getPath(), Charset.defaultCharset().name(), Locale.KOREA);
    assertEquals(f.locale(), Locale.KOREA);
    f.close();
    try {
        f = new Formatter(notExist.getPath(), "ISO 1111-1", Locale.CHINA);
        fail("should throw UnsupportedEncodingException");
    } catch (UnsupportedEncodingException e1) {
    // expected
    }
    f = new Formatter(fileWithContent.getPath(), "UTF-16BE", Locale.CANADA_FRENCH);
    assertEquals(0, fileWithContent.length());
    f.close();
    if (!root) {
        try {
            f = new Formatter(readOnly.getPath(), Charset.defaultCharset().name(), Locale.ITALY);
            fail("should throw FileNotFoundException");
        } catch (FileNotFoundException e) {
        // expected
        }
    }
}
Also used : Formatter(java.util.Formatter) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1401 IOException (java.io.IOException)385 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)150 ArrayList (java.util.ArrayList)129 File (java.io.File)120 InputStream (java.io.InputStream)117 ByteArrayInputStream (java.io.ByteArrayInputStream)107 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 InputStreamReader (java.io.InputStreamReader)91 MessageDigest (java.security.MessageDigest)87 OutputStreamWriter (java.io.OutputStreamWriter)83 FileNotFoundException (java.io.FileNotFoundException)79 BufferedReader (java.io.BufferedReader)73 URL (java.net.URL)73 HashMap (java.util.HashMap)66 Map (java.util.Map)63 FileOutputStream (java.io.FileOutputStream)56 List (java.util.List)46 JSONException (org.json.JSONException)45 FileInputStream (java.io.FileInputStream)41