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));
}
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;
}
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);
}
}
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);
}
}
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
}
}
}
Aggregations