0

ObjectInputStreamに問題があります。EOFエラーで読み取りに失敗する簡単なテストを作成しました。任意の入力をいただければ幸いです。

public class Test
{  
    @Test
    public void testObjectStreams( ) throws IOException, ClassNotFoundException
    {     
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);

        String stringTest = "TEST";
        oos.writeObject( stringTest );

        oos.close();
        baos.close();

        byte[] bytes = baos.toByteArray();
        String hexString = DatatypeConverter.printHexBinary( bytes);
        byte[] reconvertedBytes = DatatypeConverter.parseHexBinary(hexString);

        assertArrayEquals( bytes, reconvertedBytes );

        ByteArrayInputStream bais = new ByteArrayInputStream(reconvertedBytes);
        ObjectInputStream ois = new ObjectInputStream(bais);

        String readString = (String) ois.readObject();

        assertEquals( stringTest, readString);
    }
}
4

0 に答える 0