use of java.nio.charset.UnmappableCharacterException in project robovm by robovm.
the class CharsetEncoderTest method testEncodeCharBufferException.
public void testEncodeCharBufferException() throws CharacterCodingException {
ByteBuffer out;
CharBuffer in;
// MalformedException:
in = getMalformedCharBuffer();
encoder.onMalformedInput(CodingErrorAction.REPORT);
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
if (in != null) {
try {
// regression test for Harmony-1379
encoder.encode(in);
fail("should throw MalformedInputException");
} catch (MalformedInputException e) {
}
encoder.reset();
in.rewind();
encoder.onMalformedInput(CodingErrorAction.IGNORE);
out = encoder.encode(in);
assertByteArray(out, addSurrogate(unibytes));
encoder.reset();
in.rewind();
encoder.onMalformedInput(CodingErrorAction.REPLACE);
out = encoder.encode(in);
assertByteArray(out, addSurrogate(unibytesWithRep));
}
// Unmapped Exception:
in = getUnmapCharBuffer();
encoder.onMalformedInput(CodingErrorAction.REPORT);
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
if (in != null) {
encoder.reset();
try {
encoder.encode(in);
fail("should throw UnmappableCharacterException");
} catch (UnmappableCharacterException e) {
}
encoder.reset();
in.rewind();
encoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
out = encoder.encode(in);
assertByteArray(out, unibytes);
encoder.reset();
in.rewind();
encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
out = encoder.encode(in);
assertByteArray(out, unibytesWithRep);
}
// RuntimeException
try {
encoder.encode(getExceptionCharBuffer());
fail("should throw runtime exception");
} catch (RuntimeException e) {
}
}
use of java.nio.charset.UnmappableCharacterException in project jdk8u_jdk by JetBrains.
the class BytesAndLines method testWriteLines.
/**
* Exercise Files.write(Path, Iterable<? extends CharSequence>, Charset, OpenOption...)
*/
public void testWriteLines() throws IOException {
// zero lines
Path result = Files.write(tmpfile, Collections.<String>emptyList(), US_ASCII);
assert (Files.size(tmpfile) == 0);
assert (result == tmpfile);
// two lines
List<String> lines = Arrays.asList("hi", "there");
Files.write(tmpfile, lines, US_ASCII);
List<String> actual = Files.readAllLines(tmpfile, US_ASCII);
assertTrue(actual.equals(lines), "Unexpected lines");
// append two lines
Files.write(tmpfile, lines, US_ASCII, APPEND);
List<String> expected = new ArrayList<>();
expected.addAll(lines);
expected.addAll(lines);
assertTrue(expected.size() == 4, "List should have 4 elements");
actual = Files.readAllLines(tmpfile, US_ASCII);
assertTrue(actual.equals(expected), "Unexpected lines");
// UnmappableCharacterException
try {
String s = " ¡";
Files.write(tmpfile, Arrays.asList(s), US_ASCII);
fail("UnmappableCharacterException expected");
} catch (UnmappableCharacterException ignore) {
}
}
use of java.nio.charset.UnmappableCharacterException in project jdk8u_jdk by JetBrains.
the class DiacriticTest method main.
public static void main(String[] args) throws IOException {
if (!isMacOSX) {
System.out.println("This test is for Mac OS X only. Passing.");
return;
}
String lang = System.getenv("LANG");
if (lang != null && !lang.contains("UTF-8")) {
System.out.println("LANG variable set to the language that " + "does not support unicode, test passes vacuously");
return;
}
File sourceFile = new File(NAME_NFC + ".java");
String source = "public class " + NAME_NFC + " { " + " public static void main(String args[]) {\n" + " System.out.println(\"Success!\");\n" + " }\n" + "}\n";
ArrayList<String> content = new ArrayList<>();
content.add(source);
try {
createFile(sourceFile, content);
} catch (UnmappableCharacterException | InvalidPathException ipe) {
System.out.println("The locale or file system is configured in a way " + "that prevents file creation. Real testing impossible.");
return;
}
HashMap<String, String> env = new HashMap<>();
env.put("LC_CTYPE", "UTF-8");
TestResult tr;
tr = doExec(env, javacCmd, NAME_NFD + ".java");
System.out.println(tr.testOutput);
if (!tr.isOK()) {
System.out.println(tr);
throw new RuntimeException("Compilation failed");
}
tr = doExec(env, javaCmd, "-cp", ".", NAME_NFD);
System.out.println(tr.testOutput);
if (!tr.isOK()) {
System.out.println(tr);
throw new RuntimeException("Test execution failed");
}
}
Aggregations