Signed Applet - Problem reading large local files

Hello,

I am using a signed applet (self-signed) to read files from a clients machine (local file system). Following is the code for buffered reading (the meat):

String thisLine, ret = "";

try{

BufferedReader myInput = new BufferedReader(new FileReader(fn));

while ((thisLine = myInput.readLine()) != null) {

ret += thisLine + "\n";

}

myInput.close();

}

catch (Exception e) {

ret = "Cannot load, exception!";

}

When I read a file <= 512KB, it runs fine/as expected. Now, when I read a file, say for example 1024KB in size, I expect the application to take twice as much time (than 512KB file) and read the file, but instead the applet/browser hangs. As a matter of fact I am not able to read files > 512KB.

So, is there a limit on file size (from local file system) when reading from an applet, or is it to do with the way I am reading it?

Any help, suggestions or comments would be highly appreciated.

Thanks in advance.

[1030 byte] By [saeenalia] at [2007-10-1 0:07:18]
# 1

Here is how I read a file from my applet:

private String getData(String u) {

URL url = null;

InputStream in = null;

String ret = null;

try {

// the following line wil read a file @ the same location as your class file

// this way your applet does not need any special privileges

// you could change the url to a file if so needed

url = new URL(this.getCodeBase(), u);

URLConnection conn = url.openConnection();

// next line is optional and just tells the http server

// a utf-8 response is accepted

// some servers will return a bad request

conn.setRequestProperty("Accept-Charset","utf-8");

// first try to find out if the server has

// provided us with the charset of the response

// since this doesn't work with the msjvp (version 1.1.2)

// it's commented out

// instead provide a charEncoding yourselve

String charEncoding = "UTF8";

//int i = conn.getHeaderFields().size()-1;

//while(i>-1){

//System.out.print(conn.getHeaderFieldKey(i));

//System.out.print("=");

//System.out.println(conn.getHeaderField(i));

//if(conn.getHeaderField(i).toLowerCase().indexOf("charset")!=-1){

//String charsetLine = conn.getHeaderField(i).toUpperCase();

//if(charsetLine.indexOf("SHIFT_JIS")!=-1){

//charEncoding = "Shift_JIS";

//}

//if(charsetLine.indexOf("EUC-JP")!=-1){

//charEncoding = "EUC-JP";

//}

//}

//i--;

//}

// here is the value for char encoding (as a parameter in the <object html tag)

if(this.getParameter("dataCharset")!=null){

charEncoding=this.getParameter("dataCharset");

}

// wither you have a file or an url you read from an inputstream

// here is how it's done

// read the whole file and than turn it into a string

in = conn.getInputStream();

ByteArrayOutputStream bos = new ByteArrayOutputStream();

int len;

byte[] buf = new byte[1024];

while ((len = in.read(buf)) > 0) {

bos.write(buf, 0, len);

}

in.close();

// you have the file as a byte array (bos.toByteArray()

// here is how you turn it into a string

ret = new String(bos.toByteArray(),charEncoding);

} catch (Exception e) {

e.printStackTrace(System.out);

}

return ret;

}

harmmeijera at 2007-7-7 15:51:21 > top of Java-index,Security,Signed Applets...