FileDocCategorySizeDatePackage
ChannelsTest.javaAPI DocAndroid 1.5 API37802Wed May 06 22:41:04 BST 2009org.apache.harmony.nio.tests.java.nio.channels

ChannelsTest

public class ChannelsTest extends TestCase
Note: the test case uses a temp text file named "test" which contains 31 characters : "P@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]"

Fields Summary
private static final String
CODE_SET
private static final String
BAD_CODE_SET
private FileInputStream
fins
private FileOutputStream
fouts
private final int
writebufSize
private final int
testNum
private final int
fileSize
private File
tmpFile
Constructors Summary
Methods Summary
private voidassertFileSizeSame(java.io.File fileToTest, int compareNumber)

        FileInputStream file = new FileInputStream(fileToTest);
        assertEquals(file.available(), compareNumber);
        file.close();
    
protected voidsetUp()


         
        super.setUp();
        // Make the test file same in every test
        tmpFile = File.createTempFile("test","tmp");
        tmpFile.deleteOnExit();
        this.writeFileSame();
    
protected voidtearDown()

        if (null != this.fins) {
            this.fins.close();
            this.fins = null;
        }
        if (null != this.fouts) {
            this.fouts.close();
            this.fouts = null;
        }

        tmpFile.delete();
        super.tearDown();

    
public voidtestNewChannelInputStream()

        int bufSize = 10;
        int readres = 0;
        byte[] byteArray = new byte[bufSize];
        ByteBuffer byteBuf = ByteBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        readres = this.fins.read(byteArray);

        assertEquals(bufSize, readres);
        assertFalse(0 == this.fins.available());

        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        // fins still reads.
        assertFalse(0 == this.fins.available());
        readres = this.fins.read(byteArray);
        assertEquals(bufSize, readres);

        // rbChannel also reads.
        assertNotNull(rbChannel);
        readres = rbChannel.read(byteBuf);

        assertEquals(bufSize, readres);
        InputStream ins = Channels.newInputStream(rbChannel);
        assertNotNull(ins);
        assertEquals(0, ins.available());
    
public voidtestNewChannelInputStream_BufferNull()

        ByteBuffer byteBuf = ByteBuffer.allocate(this.testNum);
        int readres = this.testNum;
        this.fins = new FileInputStream(tmpFile);
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        assertNotNull(rbChannel);
        try {
            readres = rbChannel.read(null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(this.testNum, readres);
        readres = 0;
        try {
            readres = rbChannel.read(byteBuf);
        } catch (NullPointerException e) {
            fail();
        }
        assertEquals(this.testNum, readres);
    
public voidtestNewChannelInputStream_InputNull()

        ByteBuffer byteBuf = ByteBuffer.allocate(this.testNum);
        this.fins = null;
        int readres = this.testNum;
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        assertNotNull(rbChannel);
        try {
            readres = rbChannel.read(byteBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(this.testNum, readres);
    
public voidtestNewChannelOutputStream()

        int writeNum = 0;
        ByteBuffer writebuf = ByteBuffer.allocateDirect(this.writebufSize);
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf.putChar((char) (val + 64));
        }
        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel testChannel = this.fouts.getChannel();
        WritableByteChannel rbChannel = Channels.newChannel(this.fouts);

        assertTrue(testChannel.isOpen());
        assertTrue(rbChannel.isOpen());

        byte[] bit = new byte[1];
        bit[0] = 80;
        this.fouts.write(bit);
        this.fouts.flush();
        this.fins = new FileInputStream(tmpFile);
        assertEquals(this.fins.available(), 1);
        this.fins.close();

        writeNum = rbChannel.write(writebuf);
        // write success ,but output null
        assertEquals(0, writeNum);
        // close of fouts does not affect on channel
        this.fouts.close();
        writeNum = rbChannel.write(writebuf);
        assertEquals(0, writeNum);
        try {
            writeNum = testChannel.write(writebuf);
            fail();
        } catch (ClosedChannelException e) {
            // correct
        }
        assertEquals(0, writeNum);
        // close of rbchannel does affect on testchannel(same channel)
        rbChannel.close();
        try {
            writeNum = testChannel.write(writebuf);
            fail();
        } catch (ClosedChannelException e) {
            // correct
        }
    
public voidtestNewChannelOutputStream_BufNull()

        int writeres = this.testNum;
        ByteBuffer writebuf = null;
        try {
            this.fouts = new FileOutputStream(tmpFile);
        } catch (FileNotFoundException e) {
            fail();
        }

        WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
        try {
            writeres = rbChannel.write(writebuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(this.testNum, writeres);
    
public voidtestNewChannelOutputStream_inputNull()

        int writeres = this.testNum;
        ByteBuffer writebuf = ByteBuffer.allocate(this.writebufSize);
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf.putChar((char) (val + 64));
        }
        this.fouts = null;
        WritableByteChannel rbChannel = Channels.newChannel(this.fouts);
        writeres = rbChannel.write(writebuf);
        assertEquals(0, writeres);

        writebuf.flip();
        try {
            writeres = rbChannel.write(writebuf);
            fail("Should throw NPE.");
        } catch (NullPointerException e) {
        }
    
public voidtestNewInputStreamReadableByteChannel()

        ByteBuffer readbcbuf = ByteBuffer.allocateDirect(this.testNum);
        byte[] readbuf = new byte[this.testNum];
        this.fins = new FileInputStream(tmpFile);
        ReadableByteChannel readbc = this.fins.getChannel();
        assertEquals(this.fileSize, this.fins.available());
        assertTrue(readbc.isOpen());
        InputStream testins = Channels.newInputStream(readbc);
        // read in testins and fins use the same pointer
        testins.read(readbuf);
        assertEquals(this.fins.available(), this.fileSize - this.testNum);
        int readNum = readbc.read(readbcbuf);
        assertEquals(readNum, this.testNum);
        assertEquals(this.fins.available(), this.fileSize - this.testNum * 2);
        testins.read(readbuf);
        assertEquals(this.fins.available(), this.fileSize - this.testNum * 3);

        assertFalse(testins.markSupported());
        try {
            testins.mark(10);
        } catch (UnsupportedOperationException e) {
            // expected;
        }

        try {
            testins.reset();
        } catch (IOException e) {
            // expected;
        }

        // readbc.close() affect testins
        readbc.close();
        assertFalse(readbc.isOpen());
        try {
            testins.read(readbuf);
            fail();
        } catch (ClosedChannelException e) {
            // correct
        }

        // Read methods throw IllegalBlockingModeException if underlying channel
        // is in non-blocking mode.
        SocketChannel chan = SocketChannel.open();
        chan.configureBlocking(false);
        testins = Channels.newInputStream(chan);
        try {
            testins.read();
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            testins.read(new byte[1]);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            testins.read(new byte[1], 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
    
public voidtestNewInputStreamReadableByteChannel_InputNull()

        byte[] readbuf = new byte[this.testNum];
        this.fins = new FileInputStream(tmpFile);
        ReadableByteChannel readbc = this.fins.getChannel();
        assertEquals(this.fileSize, this.fins.available());
        assertTrue(readbc.isOpen());
        InputStream testins = Channels.newInputStream(null);
        assertNotNull(testins);

        try {
            testins.read(readbuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(0, testins.available());
        try {
            testins.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }

    
public voidtestNewOutputStreamWritableByteChannel()

        byte[] writebuf = new byte[this.testNum];
        ByteBuffer writebcbuf = ByteBuffer.allocateDirect(this.testNum);
        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel writebc = this.fouts.getChannel();

        assertTrue(writebc.isOpen());
        OutputStream testouts = Channels.newOutputStream(writebc);

        // read in testins and fins use the same pointer
        testouts.write(writebuf);
        this.assertFileSizeSame(tmpFile, this.testNum);
        writebc.write(writebcbuf);
        this.assertFileSizeSame(tmpFile, this.testNum * 2);
        testouts.write(writebuf);
        this.assertFileSizeSame(tmpFile, this.testNum * 3);
        // readbc.close() affect testins
        writebc.close();
        assertFalse(writebc.isOpen());
        try {
            testouts.write(writebuf);
            fail();
        } catch (ClosedChannelException e) {
            // correct
        }

        // Write methods throw IllegalBlockingModeException if underlying 
        // channel is in non-blocking mode.
        SocketChannel chan = SocketChannel.open();
        chan.configureBlocking(false);
        testouts = Channels.newOutputStream(chan);
        try {
            testouts.write(10);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            testouts.write(new byte[1]);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            testouts.write(new byte[1], 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
    
public voidtestNewOutputStreamWritableByteChannel_InputNull()

        byte[] writebuf = new byte[this.testNum];
        OutputStream testouts = Channels.newOutputStream(null);
        assertNotNull(testouts);
        try {
            testouts.write(writebuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        testouts.flush();
        try {
            testouts.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        WritableByteChannel writebc = Channels.newChannel((OutputStream) null);
        assertTrue(writebc.isOpen());
        OutputStream testoutputS = Channels.newOutputStream(writebc);
        try {
            testoutputS.write(writebuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewReaderReadableByteChannel()

        int bufSize = this.testNum;
        int readres = 0;
        CharBuffer charBuf = CharBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        Reader testReader = Channels.newReader(rbChannel, Charset.forName(
                CODE_SET).newDecoder(), //$NON-NLS-1$
                -1);
        Reader testReader_s = Channels.newReader(rbChannel, CODE_SET); //$NON-NLS-1$

        assertEquals(this.fileSize, this.fins.available());
        // not ready...
        assertFalse(testReader.ready());
        assertFalse(testReader_s.ready());
        // still reads
        readres = testReader.read(charBuf);
        assertEquals(bufSize, readres);
        assertEquals(0, this.fins.available());

        try {
            readres = testReader.read((CharBuffer) null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }

        readres = testReader_s.read(charBuf);
        assertEquals(0, readres);
        assertTrue(testReader.ready());
        assertFalse(testReader_s.ready());
    
public voidtestNewReaderReadableByteChannelCharsetDecoderI_InputNull()

        int bufSize = this.testNum;
        int readres = 0;
        CharBuffer charBuf = CharBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        // channel null
        Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
                .newDecoder(), -1);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read((CharBuffer) null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(0, readres);
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }

        this.fins = null;
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        // channel with null inputs
        testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
                .newDecoder(), //$NON-NLS-1$
                -1);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewReaderReadableByteChannelCharsetDecoderI_internalBufferZero()

        int bufSize = this.testNum;
        int readres = 0;
        CharBuffer charBuf = CharBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        // channel null
        Reader testReader = Channels.newReader(null, Charset.forName(CODE_SET)
                .newDecoder(), //$NON-NLS-1$
                0);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read((CharBuffer) null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(0, readres);
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        this.fins = null;
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        // channel with null inputs
        testReader = Channels.newReader(rbChannel, Charset.forName(CODE_SET)
                .newDecoder(), //$NON-NLS-1$
                -1);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewReaderReadableByteChannelString_InputNull()

        int bufSize = this.testNum;
        int readres = 0;
        CharBuffer charBuf = CharBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        // channel null
        Reader testReader = Channels.newReader(null, CODE_SET);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read((CharBuffer) null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(0, readres);
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }

        this.fins = null;
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        // channel with null inputs
        testReader = Channels.newReader(rbChannel, CODE_SET);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewReaderReadableByteChannelString_internalBufferZero()

        int bufSize = this.testNum;
        int readres = 0;
        CharBuffer charBuf = CharBuffer.allocate(bufSize);
        this.fins = new FileInputStream(tmpFile);
        // channel null
        Reader testReader = Channels.newReader(null, CODE_SET);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read((CharBuffer) null);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        assertEquals(0, readres);
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        this.fins = null;
        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        // channel with null inputs
        testReader = Channels.newReader(rbChannel, CODE_SET);
        assertNotNull(testReader);
        assertFalse(testReader.ready());
        try {
            readres = testReader.read(charBuf);
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewWriterWritableByteChannelCharsetEncoderI_InputNull()

        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        Writer testWriter = Channels.newWriter(wbChannel, Charset.forName(
                CODE_SET).newEncoder(), //$NON-NLS-1$
                1);

        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        // can write to buffer
        testWriter.write(writebuf);
        testWriter.flush();
        testWriter.close();

    
public voidtestNewWriterWritableByteChannelCharsetEncoderI_internalBufZero()


        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        // null channel
        Writer testWriter = Channels.newWriter(null, Charset.forName(CODE_SET)
                .newEncoder(), //$NON-NLS-1$
                -1);
        // can write to buffer
        testWriter.write(writebuf);
        try {
            testWriter.flush();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        try {
            testWriter.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }

        // channel with null input
        this.fouts = null;
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        testWriter = Channels.newWriter(wbChannel, Charset.forName(CODE_SET)
                .newEncoder(), //$NON-NLS-1$
                -1);
        // can write to buffer
        testWriter.write(writebuf);
        try {
            testWriter.flush();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        try {
            testWriter.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtestNewWriterWritableByteChannelString()

        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        Writer testWriter = Channels.newWriter(wbChannel, CODE_SET); //$NON-NLS-1$
        Writer testWriter_s = Channels.newWriter(wbChannel, Charset.forName(
                CODE_SET).newEncoder(), //$NON-NLS-1$
                -1);

        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        byte[] bit = new byte[1];
        bit[0] = 80;
        this.fouts.write(bit);
        this.assertFileSizeSame(tmpFile, 1);

        // writer continues to write after '1',what the fouts write
        testWriter.write(writebuf);
        testWriter.flush();
        this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
        // testwriter_s does not know if testwrite writes
        testWriter_s.write(writebuf);
        testWriter.flush();
        this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
        // testwriter_s even does not know if himself writes?
        testWriter_s.write(writebuf);
        testWriter.flush();
        this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);

        // close the fouts, no longer writable for testWriter
        for (int val = 0; val < this.writebufSize; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        this.fouts.close();
        testWriter_s.write(writebuf);
        testWriter.flush();
        this.assertFileSizeSame(tmpFile, this.writebufSize / 2 + 1);
        
        SocketChannel chan = SocketChannel.open();
        chan.configureBlocking(false);
        Writer writer = Channels.newWriter(chan, CODE_SET);
        try {
            writer.write(10);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write(new char[10]);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write("test");
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write(new char[10], 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write("test", 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        
        writer = Channels.newWriter(chan, Charset.forName(
                CODE_SET).newEncoder(), //$NON-NLS-1$
                -1);
        try {
            writer.write(10);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write(new char[10]);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write("test");
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write(new char[10], 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
        try {
            writer.write("test", 0, 1);
        } catch (IllegalBlockingModeException e) {
            // expected
        }
    
public voidtestNewWriterWritableByteChannelString_InputNull()

        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        Writer testWriter = Channels.newWriter(wbChannel, CODE_SET);

        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        // can write to buffer
        testWriter.write(writebuf);
        testWriter.flush();
        testWriter.close();

    
public voidtestNewWriterWritableByteChannelString_internalBufZero()


        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        // null channel
        Writer testWriter = Channels.newWriter(null, CODE_SET);
        // can write to buffer
        testWriter.write(writebuf);
        try {
            testWriter.flush();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        try {
            testWriter.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }

        // channel with null input
        this.fouts = null;
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        testWriter = Channels.newWriter(wbChannel, CODE_SET);
        // can write to buffer
        testWriter.write(writebuf);
        try {
            testWriter.flush();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
        try {
            testWriter.close();
            fail();
        } catch (NullPointerException e) {
            // correct
        }
    
public voidtest_newInputStream_LReadableByteChannel()

tests
java.nio.channels.Channels#newReader(ReadableByteChannel channel, String charsetName)

        InetSocketAddress localAddr = new InetSocketAddress("127.0.0.1",
                Support_PortManager.getNextPort());
        ServerSocketChannel ssc = ServerSocketChannel.open();
        ssc.socket().bind(localAddr);

        SocketChannel sc = SocketChannel.open();
        sc.connect(localAddr);
        sc.configureBlocking(false);
        assertFalse(sc.isBlocking());

        ssc.accept().close();
        ssc.close();
        assertFalse(sc.isBlocking());

        Reader reader = Channels.newReader(sc, "UTF16");
        int i = reader.read();
        assertEquals(-1, i);

        try {
            Channels.newInputStream(sc).read();
            fail("should throw IllegalBlockingModeException");
        } catch (IllegalBlockingModeException e) {
            // expected
        }

        sc.close();
    
public voidtestnewReaderCharsetError()

        this.fins = new FileInputStream(tmpFile);

        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        try {
            Channels.newReader(rbChannel, Charset.forName(BAD_CODE_SET)
                    .newDecoder(), //$NON-NLS-1$
                    -1);
            fail();
        } catch (UnsupportedCharsetException e) {
            // correct
        }
    
public voidtestnewReaderCharsetError2()

        this.fins = new FileInputStream(tmpFile);

        ReadableByteChannel rbChannel = Channels.newChannel(this.fins);
        try {
            Channels.newReader(rbChannel, BAD_CODE_SET);
            fail();
        } catch (UnsupportedCharsetException e) {
            // correct
        }
    
public voidtestnewWriterCharsetError()

        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        try {
            Channels.newWriter(wbChannel, Charset.forName(BAD_CODE_SET)
                    .newEncoder(), -1);
            fail();
        } catch (UnsupportedCharsetException e) {
            // correct
        }
    
public voidtestnewWriterCharsetError2()

        this.fouts = new FileOutputStream(tmpFile);
        WritableByteChannel wbChannel = Channels.newChannel(this.fouts);
        try {
            Channels.newWriter(wbChannel, BAD_CODE_SET);
            fail();
        } catch (UnsupportedCharsetException e) {
            // correct
        }
    
private voidwriteFileSame()

        this.fouts = new FileOutputStream(tmpFile);
        byte[] bit = new byte[1];
        bit[0] = 80;
        this.fouts.write(bit);
        this.fouts.flush();
        String writebuf = ""; //$NON-NLS-1$
        for (int val = 0; val < this.writebufSize / 2; val++) {
            writebuf = writebuf + ((char) (val + 64));
        }
        this.fouts.write(writebuf.getBytes());