OutputStreamWriter extends Writer { @Override public void write(char[] chars) throws IOException { _write(CharBuffer.wrap(chars, 0, chars.length)); } OutputStreamWriter(OutputStream outputStream);  OutputStreamWriter(OutputStream outputStream, String charsetName);  OutputStreamWriter(
		OutputStream outputStream, String charsetName, boolean autoFlush);  OutputStreamWriter(
		OutputStream outputStream, String charsetName, int outputBufferSize);  OutputStreamWriter(
		OutputStream outputStream, String charsetName, int outputBufferSize,
		boolean autoFlush); @Override void close(); @Override void flush(); String getEncoding(); @Override void write(char[] chars); @Override void write(char[] chars, int offset, int length); @Override void write(int c); @Override void write(String string); @Override void write(String string, int offset, int length);  }
@Test public void testWriteError() throws IOException { OutputStreamWriter outputStreamWriter = new OutputStreamWriter( new DummyOutputStream(), "US-ASCII"); CharsetEncoder charsetEncoder = ReflectionTestUtil.getFieldValue( outputStreamWriter, "_charsetEncoder"); charsetEncoder.onUnmappableCharacter(CodingErrorAction.REPORT); try { outputStreamWriter.write("测试"); Assert.fail(); } catch (UnmappableCharacterException unmappableCharacterException) { Assert.assertEquals( 1, unmappableCharacterException.getInputLength()); } }
@Test public void testWriteIntUnicodeSurrogatePair() throws IOException { _testUnicodeSurrogatePair( (outputStreamWriter, surrogatePair) -> { outputStreamWriter.write(surrogatePair[0]); outputStreamWriter.write(surrogatePair[1]); }); _testUnicodeSurrogatePair( (outputStreamWriter, surrogatePair) -> { outputStreamWriter.write(surrogatePair[0]); outputStreamWriter.write(new char[] {surrogatePair[1]}); }); _testUnicodeSurrogatePair( (outputStreamWriter, surrogatePair) -> { outputStreamWriter.write(new char[] {surrogatePair[0]}); outputStreamWriter.write(surrogatePair[1]); }); _testUnicodeSurrogatePair( (outputStreamWriter, surrogatePair) -> { outputStreamWriter.write(new char[] {surrogatePair[0]}); outputStreamWriter.write(new char[] {surrogatePair[1]}); }); }