kalpana
Posts: 2
Nickname: kalpana
Registered: Feb, 2002
|
|
slow painting while reading and writing doubles for MB Files
|
Posted: Mar 18, 2002 9:52 PM
|
|
Advertisement
|
for 15MB length file i = 7662080 for 50MB length file i = 12414368
Part of Code for writing into file follows like this: ---------------------------------------------------- try{ fos = new FileOutputStream("Angel.txt"); File f = new File("Angel.txt"); if(f.length() >=4) { f.delete(); fos = new FileOutputStream("Angel.txt"); } dos = new DataOutputStream(new BufferedOutputStream(fos,1000000)); int x=0; double y_last, y_new; for(int j=0 ;j<i ;j++) { --- --- --- if(some condition) { y_new = ....; try{ //previously in vectors y_last = y_new; vect.add(new Line2D.Double(x, y_last, x, y_new)_; dos.writeDouble(y_new); }catch(Exception e){System.out.println(e);} } } dos.close(); fos.close(); x++; }catch(Exception excp){System.out.println(excp);}
part of code for reading from file follows like this: ----------------------------------------------------- public void paint(Graphics g) {
try{ double y1, y2 =0; Line2D.Double doub; raf = new RandomAccessFile("Angel.txt","r"); dis = new DataInputStream(new BufferedInputStream(new FileInputStream(raf.getFD(),1000000))); raf.seek((rect.x*8)); for (int i = rect.x; (i < (rect.x + rect.width)); i++) { g2.setStroke(new BasicStroke(0)); //2 y1 = y2; y2 =dis.readDouble(); doub=new Line2D.Double(i,y1,i,y2); g2.draw(doub); } dis.close(); raf.close(); }catch(Exception excp){System.out.println(excp);} }
I tried using Object Streams but NotSerializable Exception is thrown as Line2D.Double objects are not serialized.
|
|