ByteArray doen't read UTF-8

21 views
Skip to first unread message

templar

unread,
Sep 17, 2011, 9:08:01 AM9/17/11
to PulpCore
d = Download.startDownload("test.cng");

......

if(d.getState()==2){
ByteArray bytes = new ByteArray(d.getData());
try {
System.out.println(bytes.readUTF());
} catch (IndexOutOfBoundsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UTFDataFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

[pulpcore-player] java.lang.IndexOutOfBoundsException
[pulpcore-player] at
pulpcore.util.ByteArray.checkAvailable(ByteArray.java:308)
[pulpcore-player] at pulpcore.util.ByteArray.readUTF(ByteArray.java:
419)
[pulpcore-player] at Sounds.update(Sounds.java:60)
[pulpcore-player] at pulpcore.scene.Scene2D.updateScene(Scene2D.java:
700)
[pulpcore-player] at pulpcore.Stage.animationLoop(Stage.java:691)
[pulpcore-player] at pulpcore.Stage.run(Stage.java:517)
[pulpcore-player] at java.lang.Thread.run(Unknown Source)

David Brackeen

unread,
Sep 17, 2011, 10:52:07 AM9/17/11
to pulp...@googlegroups.com
Does it work if you wrap the byte[] array in a ByteArrayInputStream and DataInputStream?


--
You received this message because you are subscribed to the Google Groups "PulpCore" group.
To post to this group, send email to pulp...@googlegroups.com.
To unsubscribe from this group, send email to pulpcore+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pulpcore?hl=en.


templar

unread,
Sep 17, 2011, 2:15:28 PM9/17/11
to PulpCore
new String(d.getData(), "UTF-8"); after it I have found that there is
one more symbols. I am using notepad to save file in UTF-8 (mb problem
in notepad?).

On Sep 17, 5:52 pm, David Brackeen <brack...@gmail.com> wrote:
> Does it work if you wrap the byte[] array in a ByteArrayInputStream and
> DataInputStream?
>

David Brackeen

unread,
Sep 17, 2011, 2:18:33 PM9/17/11
to pulp...@googlegroups.com
ByteArray really just reads strings encoded via something like DataOutputStream.
In your case, you probably want an InputStreamReader
Reply all
Reply to author
Forward
0 new messages