[Biojava-l] Error while reading byte data for creating a Trace.
abhinav
abhi232 at cc.gatech.edu
Tue Nov 6 18:03:02 UTC 2007
Richard Holland wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> I think that either the file is at fault, or the method you are using to
> read the file into Java is at fault.
>
> Could you provide us with the complete piece of code you are using from
> the point where you read the file into the array through to the point
> where you generate the output you quoted? (Not as an attachment as the
> mailing list will strip those - simply paste it into the message body
> instead).
>
> cheers,
> Richard
>
>
> abhinav wrote:
>
>> Richard Holland wrote:
>> I suspect the byte array itself may contain inaccurate data.
>>
>> Internally, both the URL and File constructors read the data into a byte
>> array and then pass it to the same method as is used by the byte[]
>> constructor.
>>
>> So, something must be different between the byte array you have, and the
>> byte array obtained by reading the file in.
>>
>> The File constructor uses the following code to read the file:
>>
>> byte[] bytes = null;
>> ByteArrayOutputStream baos = new ByteArrayOutputStream();
>> FileInputStream fis = new FileInputStream(ABIFile);
>> BufferedInputStream bis = new BufferedInputStream(fis);
>> int b;
>> while ((b = bis.read()) >= 0)
>> {
>> baos.write(b);
>> }
>> bis.close(); fis.close(); baos.close();
>> bytes = baos.toByteArray();
>>
>> If the above code produces different results to your byte array when
>> reading data from the same file as your code, then something has gone
>> wrong with the construction of your byte array.
>>
>> Lastly, a full stack trace would help us pinpoint the line that is
>> breaking, and hopefully provide a hint as to what is wrong with the
>> contents of the byte array. If you could provide one that would be very
>> helpful.
>>
>> cheers,
>> Richard
>>
>>
>> abhi232 at cc.gatech.edu wrote:
>>
>>
>>>>> Hi all,
>>>>> I am having a byte array which is having the data from an .ab1 file.The
>>>>> biojava library provides a class called as ABITrace which takes as input
>>>>> either a byte[] array , a file or a url.If i use the later parameters (the
>>>>> file or the url )the program works but if I pass the byte array to the
>>>>> constructor I get java.lang.arrayIndexOutOfBound.Exception.Is there a
>>>>> problem with the ABITrace class or how can I bypass this particular error.
>>>>> I am printing the length of the byte array and it comes to 144930...Can
>>>>> that cause a problem in my code?
>>>>>
>>>>> Thanks in advance.
>>>>> Abhinav
>>>>> _______________________________________________
>>>>> Biojava-l mailing list - Biojava-l at lists.open-bio.org
>>>>> http://lists.open-bio.org/mailman/listinfo/biojava-l
>>>>>
>>>>>
>>>>>
>
>
>> Yes I looked at the file ABITrace and found out that the first three
>> characters must be ABI or the 128-130 characters must be ABI.But I
>> cannot find that in the file that I am having.Also If this is not the
>> case then there should be an illegal format exception whereas I am
>> arrayIndexOutOfBound Exception which is also weird.
>> I am getting the following stack trace.
>> The bytes that i want are:0
>> The bytes that i want are:11
>> The bytes that i want are:0
>> The size of the byte array generated is:144930
>> Byte array also recieved
>> java.lang.ArrayIndexOutOfBoundsException: 128
>> at org.biojava.bio.program.abi.ABITrace.isABI(ABITrace.java:552)
>> at org.biojava.bio.program.abi.ABITrace.initData(ABITrace.java:289)
>> at org.biojava.bio.program.abi.ABITrace.<init>(ABITrace.java:136)
>> at Trace.init(Trace.java:138)
>> at sun.applet.AppletPanel.run(Unknown Source)
>> at java.lang.Thread.run(Unknown Source)
>> The bytes I want are the first three bytes that I want to check if my
>> file is ABI or not.I checked the isABI function as well it returns true
>> or false value and not arrayIndexOutOfBouond . Also the number 128 does
>> it hve any significance in this case?
>> Thanks in advance
>> Abhinav
>>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.2 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFHMJwi4C5LeMEKA/QRAhAOAJ0ZjIWk1CXSLYlU2CUCp7xodAfFeACgjtFG
> T1Z8W0JhCe7+hx5rbKLGqVk=
> =qNcr
> -----END PGP SIGNATURE-----
>
Ok Yes here is the code that i am using .I establish a connection with a
php page which in turn reads the file and prints the content back to
me.I am using DataOutputStream for sending data and BufferedReader for
taking in the data.Then I am reading the data into a string and
converting it to byte[] array . this the code where the connection is
estableshed and the data is taken and displayed.
private HttpURLConnection httpConn;
private DataOutputStream out;
private DataInputStream temp_stream;
private BufferedReader in;
private BufferedInputStream in_buff_stream;
private String str ;
private byte[] bytearray;
Chromatogram abif_chromatogram;
/** Creates a new instance of testPost */
public testPost()
{
httpConn = null;
str = new String("");
bytearray = new byte[144930];
}
public byte[] create_and_write_Connection(String url,String
data_request)
{
try
{
URL conn_url = new URL(url);
httpConn = (HttpURLConnection)conn_url.openConnection();
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
httpConn.setRequestMethod("POST");
out=new DataOutputStream(httpConn.getOutputStream());
out.writeBytes(data_request);
out.flush();
System.out.println("Connection established successfully and
data written");
InputStreamReader in_stream = new
InputStreamReader(httpConn.getInputStream());
System.out.println("The character encoding used is:"+
in_stream.getEncoding());
in = new BufferedReader(in_stream);
System.out.println("Data acceptance started");
while(in.readLine()!=null)
{
str += in.readLine();
}
System.out.println("The string to be returned is:"+str);
bytearray = str.getBytes("ISO8859-1");
String temp_string = new String(bytearray,"windows-1252");
System.out.println("The encoded string is as follows:"+
temp_string);
System.out.println("The size of byte array inside testpost
is:"+ Array.getLength(bytearray));
for(int i = 0 ; i < 3 ; i ++)
System.out.println("The bytes that i want are:"+
bytearray[i]);
return bytearray;
}
catch(Exception e)
{
e.printStackTrace();
}
return bytearray;
}
Please guide me on this point
Thanks
Abhinav
More information about the Biojava-l
mailing list