java.nio.charset.UnmappableCharacterException Java Examples
The following examples show how to use
java.nio.charset.UnmappableCharacterException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TaskScanner.java From warnings-ng-plugin with MIT License | 6 votes |
/** * Scans the specified file for open tasks. * * @param file * the file to scan * @param charset * encoding of the file * * @return the open tasks */ public Report scan(final Path file, final Charset charset) { try (Stream<String> lines = Files.lines(file, charset)) { return scanTasks(lines.iterator(), new IssueBuilder().setFileName(file.toString())); } catch (IOException | UncheckedIOException exception) { Report report = new Report(); Throwable cause = exception.getCause(); if (cause instanceof MalformedInputException || cause instanceof UnmappableCharacterException) { report.logError("Can't read source file '%s', defined encoding '%s' seems to be wrong", file, charset); } else { report.logException(exception, "Exception while reading the source code file '%s':", file); } return report; } }
Example #2
Source File: CodeSetConversion.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #3
Source File: BytesAndLines.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #4
Source File: CodeSetConversion.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #5
Source File: BytesAndLines.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #6
Source File: BytesAndLines.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #7
Source File: BytesAndLines.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #8
Source File: StringCoding.java From Bytecoder with Apache License 2.0 | 5 votes |
static byte[] getBytesNoRepl(String s, Charset cs) throws CharacterCodingException { try { return getBytesNoRepl1(s, cs); } catch (IllegalArgumentException e) { //getBytesNoRepl1 throws IAE with UnmappableCharacterException or CCE as the cause Throwable cause = e.getCause(); if (cause instanceof UnmappableCharacterException) { throw (UnmappableCharacterException)cause; } throw (CharacterCodingException)cause; } }
Example #9
Source File: CodeSetConversion.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #10
Source File: DataEditorSupportEncodingTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testIncompatibleCharacter() throws Exception { DataObject d = DataObject.find(testFileObject); encodingName = "ISO-8859-1"; // NOI18N EditorCookie o = d.getLookup().lookup(EditorCookie.class); StyledDocument doc = o.openDocument(); doc.insertString(0, CZECH_STRING_UTF, null); try { o.saveDocument(); // try to open the file InputStream istm = testFileObject.getInputStream(); try { BufferedReader r = new BufferedReader(new InputStreamReader(istm, "ISO-8859-2")); // NOI18N String line = r.readLine(); int questionMarkPos = line.indexOf('?'); // NOI18N assertTrue("Should save question marks", questionMarkPos != -1); // NOI18N } finally { istm.close(); } //fail("Exception expected"); } catch (UnmappableCharacterException ex) { // expected exceptiom } }
Example #11
Source File: BytesAndLines.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #12
Source File: CodeSetConversion.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #13
Source File: BytesAndLines.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #14
Source File: CodeSetConversion.java From hottub with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #15
Source File: BytesAndLines.java From hottub with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #16
Source File: BytesAndLines.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #17
Source File: CodeSetConversion.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #18
Source File: ISOCharsetEncoderTest.java From j2objc with Apache License 2.0 | 5 votes |
public void testMultiStepEncode() throws CharacterCodingException { encoder.onMalformedInput(CodingErrorAction.REPORT); encoder.onUnmappableCharacter(CodingErrorAction.REPORT); try { encoder.encode(CharBuffer.wrap("\ud800\udc00")); fail("should unmappable"); } catch (UnmappableCharacterException e) { } encoder.reset(); }
Example #19
Source File: BytesAndLines.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #20
Source File: CodeSetConversion.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #21
Source File: CodeSetConversion.java From JDKSourceCode1.8 with MIT License | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #22
Source File: CodeSetConversion.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #23
Source File: BytesAndLines.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #24
Source File: BytesAndLines.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #25
Source File: BytesAndLines.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #26
Source File: CodeSetConversion.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private void convertCharArray() { try { // Possible optimization of directly converting into the CDR buffer. // However, that means the CDR code would have to reserve // a 4 byte string length ahead of time, and we'd need a // confusing partial conversion scheme for when we couldn't // fit everything in the buffer but needed to know the // converted length before proceeding due to fragmentation. // Then there's the issue of the chunking code. // // For right now, this is less messy and basic tests don't // show more than a 1 ms penalty worst case. Less than a // factor of 2 increase. // Convert the characters buffer = ctb.encode(CharBuffer.wrap(chars,0,numChars)); // ByteBuffer returned by the encoder will set its limit // to byte immediately after the last written byte. numBytes = buffer.limit(); } catch (IllegalStateException ise) { // an encoding operation is already in progress throw wrapper.ctbConverterFailure( ise ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then some other encoding error occured throw wrapper.ctbConverterFailure( cce ) ; } }
Example #27
Source File: UnmappableCharacterExceptionTest.java From j2objc with Apache License 2.0 | 5 votes |
public void assertDeserialized(Serializable initial, Serializable deserialized) { // do common checks for all throwable objects SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, deserialized); UnmappableCharacterException initEx = (UnmappableCharacterException) initial; UnmappableCharacterException desrEx = (UnmappableCharacterException) deserialized; assertEquals("InputLength", initEx.getInputLength(), desrEx .getInputLength()); }
Example #28
Source File: BytesAndLines.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
/** * 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 = "\u00A0\u00A1"; Files.write(tmpfile, Arrays.asList(s), US_ASCII); fail("UnmappableCharacterException expected"); } catch (UnmappableCharacterException ignore) { } }
Example #29
Source File: CodeSetConversion.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
public char[] getChars(byte[] bytes, int offset, int numBytes) { // Possible optimization of reading directly from the CDR // byte buffer. The sun.io converter supposedly can handle // incremental conversions in which a char is broken across // two convert calls. // // Basic tests didn't show more than a 1 ms increase // worst case. It's less than a factor of 2 increase. // Also makes the interface more difficult. try { ByteBuffer byteBuf = ByteBuffer.wrap(bytes, offset, numBytes); CharBuffer charBuf = btc.decode(byteBuf); // CharBuffer returned by the decoder will set its limit // to byte immediately after the last written byte. resultingNumChars = charBuf.limit(); // IMPORTANT - It's possible the underlying char[] in the // CharBuffer returned by btc.decode(byteBuf) // is longer in length than the number of characters // decoded. Hence, the check below to ensure the // char[] returned contains all the chars that have // been decoded and no more. if (charBuf.limit() == charBuf.capacity()) { buffer = charBuf.array(); } else { buffer = new char[charBuf.limit()]; charBuf.get(buffer, 0, charBuf.limit()).position(0); } return buffer; } catch (IllegalStateException ile) { // There were a decoding operation already in progress throw wrapper.btcConverterFailure( ile ) ; } catch (MalformedInputException mie) { // There were illegal Unicode char pairs throw wrapper.badUnicodePair( mie ) ; } catch (UnmappableCharacterException uce) { // A character doesn't map to the desired code set. // CORBA formal 00-11-03. throw omgWrapper.charNotInCodeset( uce ) ; } catch (CharacterCodingException cce) { // If this happens, then a character decoding error occured. throw wrapper.btcConverterFailure( cce ) ; } }
Example #30
Source File: UnmappableCharacterExceptionTest.java From j2objc with Apache License 2.0 | 4 votes |
/** * @tests serialization/deserialization compatibility with RI. */ public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new UnmappableCharacterException( 11), COMPARATOR); }