类java.nio.charset.UnmappableCharacterException源码实例Demo

下面列出了怎么用java.nio.charset.UnmappableCharacterException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: warnings-ng-plugin   文件: TaskScanner.java
/**
 * 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;
    }
}
 
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 ) ;
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码4 项目: TencentKona-8   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码5 项目: TencentKona-8   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码6 项目: jdk8u60   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码7 项目: jdk8u60   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码8 项目: JDKSourceCode1.8   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码9 项目: openjdk-jdk8u   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码10 项目: openjdk-jdk8u   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码11 项目: netbeans   文件: DataEditorSupportEncodingTest.java
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
    }
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码14 项目: Bytecoder   文件: StringCoding.java
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;
    }
}
 
源代码15 项目: openjdk-jdk9   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码16 项目: openjdk-jdk9   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码17 项目: jdk8u-jdk   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码18 项目: hottub   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码19 项目: hottub   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码20 项目: openjdk-8-source   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码21 项目: openjdk-8-source   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码22 项目: openjdk-8   文件: CodeSetConversion.java
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 ) ;
    }
}
 
源代码23 项目: openjdk-8   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码24 项目: jdk8u_jdk   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码25 项目: jdk8u-jdk   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码26 项目: jdk8u-dev-jdk   文件: BytesAndLines.java
/**
 * 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) { }
}
 
源代码27 项目: j2objc   文件: UnmappableCharacterExceptionTest.java
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());
}
 
源代码28 项目: j2objc   文件: ISOCharsetEncoderTest.java
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();
}
 
源代码29 项目: jdk1.8-source-analysis   文件: CodeSetConversion.java
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 ) ;
            }
        }
 
源代码30 项目: dragonwell8_jdk   文件: DiacriticTest.java
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");
    }
}