How to remove CRLF(13,10) from an Byte array

i have a ByteArrayOutputStream with the following content

[13, 10, 45, 45, 95, 78, 101, 120, 116, 80, 97, 114, 116, 0]

i have check whether my stream contains a Empty Line(CRLF) which is represented by 13,10 at the begining.

if it is there i have remove that 13,10.

any body please help me out in doing this

regards

ranadheer

[369 byte] By [LoveOpensourcea] at [2007-11-27 8:50:19]
# 1

i have a ByteArrayOutputStream with the following content

[13, 10, 45, 45, 95, 78, 101, 120, 116, 80, 97, 114, 116, 0]

i have to check whether my stream contains a Empty Line(CRLF) which is represented by 13,10 at the begining.

if it is there i have remove that 13,10.

any body please help me out in doing this

regards

ranadheer

LoveOpensourcea at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 2

> i have a ByteArrayOutputStream with the following content

> [13, 10, 45, 45, 95, 78, 101, 120, 116, 80, 97, 114, 116, 0]

> i have check whether my stream contains a Empty

> Line(CRLF) which is represented by 13,10 at the begining.

> if it is there i have remove that 13,10.

> any body please help me out in doing this

> regards

> ranadheer

Create an new array of length: old array.length-2 and copy the contents from the old array (starting from index 2) to the new array

Look at the arraycopy(...) method from the System class:

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html

prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 3

thanks for u r reply.

can u give me a clue on the last parameter(lenght parameter) of arraycopy method actually i am getting exception over there. what can be the length paramater

actually my code follows

ByteArrayOutputStream baos = new ByteArrayOutputStream ();

MutableBodyMimePart mime = MimeHelper.createMimePart(transportMessage, false);

mime.setOutputStream(baos);

mime.writePart();

byte[] wholeMessage = baos.toByteArray();

//here my job starts (removing the CRLF from the baos

ByteArrayOutputStream baos1=new ByteArrayOutputStream(baos.size()-2);

System.arraycopy(baos, 2,baos1,0,baos1.size());

baos1.toByteArray();

baos.close();

baos1.close();

iam getting exception of kind

java.lang.ArrayStoreException

regards'

ranu

LoveOpensourcea at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 4

byte[] oldArray = {13, 10, 45, 45, 95, 78, 101, 120, 116, 80, 97, 114, 116, 0};

final int SKIP = 2;

byte[] newArray = new byte[oldArray.length-SKIP];

System.arraycopy(oldArray, SKIP, newArray, 0, newArray.length);

System.out.println(java.util.Arrays.toString(oldArray));

System.out.println(java.util.Arrays.toString(newArray));

prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 5
done. really wonderfulthanks and regardsranadheer
LoveOpensourcea at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 6
> done. really wonderful> thanks and regards> ranadheerYou're welcome. Of course SKIP should never exceed oldArray.length
prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 7
and by the way is there any way to check the initial bytes whether its 13,10 or notjust like using an If condition
LoveOpensourcea at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 8
and by the way is there any way to check the initial bytes whether its 13,10 or notjust like using an If conditionregardsRanadheer
LoveOpensourcea at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 9
> and by the way is there any way to check the initial> bytes whether its 13,10 or not> just like using an If condition> regards> RanadheerYes, by using the == operator.
prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 10
An additional question to that topic. What can I do if i want to remove multiple occurrences that are widespread over the array?
sonixx1408a at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 11

> An additional question to that topic. What can I do

> if i want to remove multiple occurrences that are

> widespread over the array?

I'd say use a dynamic list (like an ArrayList) to store the Bytes you're interested in. When you're done, convert it to an array of primitive bytes (if you want to). If you have more questions on the topic, I suggest creating a thread of your own about it.

prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 12
Thank you
sonixx1408a at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...
# 13
> Thank youYou're welcome.
prometheuzza at 2007-7-12 21:01:14 > top of Java-index,Java Essentials,Java Programming...