g46905
asked on
convert a the value of a string buffer to input stream
I am trying to assign the value of String buffer to an inout stream. Could someone please help me with this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
how are you reading from the stream?
ASKER
ByteArrayInputStream ba = new ByteArrayInputStream(gs.to String().g etBytes()) ;
I am passing this value as a parameter
processZipEntry(ba, size,segDelim,elemDel,from DDD,toDDD, profileNam e);
=======>>
public static void processZipEntry(InputStrea m f, int size,char segDel,char elemDel ,Date fromDDDt,Date toDDDt,String profName ) {
Vector v = new Vector();
StringBuffer sb = new StringBuffer();
try {
String stSlnValue = null;
int sBegin = 0;
size = size - HEADER_LENGTH;
for (int i=0;i<size;i++){
char c = (char)f.read();
sb.append(c);
if(sb.charAt(i) == segDel){
System.out.println(" string value stSln :" + sb.toString().trim().subst ring(sBegi n,i));
stSlnValue = sb.toString().trim().subst ring(sBegi n,i) + elemDel + profName ;
//System.out.println(" string value stSln :" + stSlnValue);
if ((stSlnValue.toString().st artsWith(" GS*FA")) || (stSlnValue.toString().sta rtsWith("S T")) || (stSlnValue.toString().sta rtsWith("S LN"))){
v.add(new String(stSlnValue));}
// if
sBegin = i + 1;
}//if condition
} // for loop
for (int j = 0; j< v.size(); j++) {
System.out.println("Vector : " + v.elementAt(j));
}
} catch (Exception e) {System.out.println(" Error while reading file into the vector " );
e.printStackTrace();} // end of try
analizeLogs(v);
sb = null;
v.clear();
}// end of the method
Please let me know if you have any questions
Thanks for your help
I am passing this value as a parameter
processZipEntry(ba, size,segDelim,elemDel,from
=======>>
public static void processZipEntry(InputStrea
Vector v = new Vector();
StringBuffer sb = new StringBuffer();
try {
String stSlnValue = null;
int sBegin = 0;
size = size - HEADER_LENGTH;
for (int i=0;i<size;i++){
char c = (char)f.read();
sb.append(c);
if(sb.charAt(i) == segDel){
System.out.println(" string value stSln :" + sb.toString().trim().subst
stSlnValue = sb.toString().trim().subst
//System.out.println(" string value stSln :" + stSlnValue);
if ((stSlnValue.toString().st
v.add(new String(stSlnValue));}
// if
sBegin = i + 1;
}//if condition
} // for loop
for (int j = 0; j< v.size(); j++) {
System.out.println("Vector
}
} catch (Exception e) {System.out.println(" Error while reading file into the vector " );
e.printStackTrace();} // end of try
analizeLogs(v);
sb = null;
v.clear();
}// end of the method
Please let me know if you have any questions
Thanks for your help
ASKER
I found whi it is not reading the first character. It is because of this particular statement.
System.out.println(" BA : " + ba.read());
I really appreciate all your help!!
Thanks again,
System.out.println(" BA : " + ba.read());
I really appreciate all your help!!
Thanks again,
no worries :)
ASKER
For example:
String Buffer GS = "ABCDEFGHI"
when I read this into input stream
I see only "BCDEFGHI"
Can you please tell me why this is happening?
Thanks,