Diff for /edoc-applet/Upload.java between versions 1.2 and 1.4

version 1.2, 2003/06/17 10:59:07 version 1.4, 2003/07/21 10:14:15
Line 3 Line 3
 //    //  
 //  //
 //  Created by rogo on Wed Jan 29 2003.  //  Created by rogo on Wed Jan 29 2003.
 //  Copyright (c) 2001 __MyCompanyName__. All rights reserved.  //  Copyright (c) 2003 Rogo Soft. All rights reserved.
 //  //
  import com.exploringxml.xml.*;   import com.exploringxml.xml.*;
  import java.io.*;   import java.io.*;
Line 20  public class Upload extends JApplet impl Line 20  public class Upload extends JApplet impl
 {  {
   static File startFile;    static File startFile;
   static int count = 0;    static int count = 0;
   static JFileChooser fileChooser;    static JFileChooser fileChooser,downloadChooser;
   static String url;    static String url;
   static long id = 0L;    static long id = 0L;
   static Hashtable connections=new Hashtable();    static Hashtable connections=new Hashtable();
   static String col = "11"; // Collection /Institute    static String col = "11"; // Collection /Institute
   static String grp ="141"; // Group or Bundle    static String grp ="136"; // Group or Bundle
   static String ses ="";    static String ses ="";
   static Bundle bundle;    static Bundle bundle;
   static Bundle bundleRef;    static Bundle bundleRef;
   JButton upload = new JButton("Upload");    JButton upload = new JButton("Upload");
     JButton download = new JButton("Download");
   JRadioButton proxy = new JRadioButton("Proxy");    JRadioButton proxy = new JRadioButton("Proxy");
   static int fileCount = 0;    static int fileCount = 0;
   // static UploadInfo dialog = new UploadInfo();    // static UploadInfo dialog = new UploadInfo();
Line 39  public class Upload extends JApplet impl Line 40  public class Upload extends JApplet impl
   Upload uploader = this;    Upload uploader = this;
   static boolean runningAsApplet=true;    static boolean runningAsApplet=true;
   static boolean debug=false;    static boolean debug=false;
     static boolean uploadMode = true;
   static String  rootNode = "edoc";    static String  rootNode = "edoc";
   static MessageDigest md ;  
   static  
   {  
       try {  
         md = MessageDigest.getInstance("MD5");  
     } catch(Exception e) { e.printStackTrace();}  
   }  
   public Upload()     public Upload() 
   {    {
     if(!runningAsApplet)      if(!runningAsApplet)
Line 58  public class Upload extends JApplet impl Line 53  public class Upload extends JApplet impl
   {    {
     this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));      this.getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER, 0, 0));
     this.getContentPane().add(upload);      this.getContentPane().add(upload);
       this.getContentPane().add(download);
     this.getContentPane().add(proxy);      this.getContentPane().add(proxy);
     upload.addActionListener(this);      upload.addActionListener(this);
       download.addActionListener(this);
     proxy.addActionListener(this);      proxy.addActionListener(this);
     id = System.currentTimeMillis();      id = System.currentTimeMillis();
        Properties prop = System.getProperties();         Properties prop = System.getProperties();
Line 68  public class Upload extends JApplet impl Line 65  public class Upload extends JApplet impl
     // prop.put("http.proxyHost","proxy.unibe.ch");      // prop.put("http.proxyHost","proxy.unibe.ch");
     // prop.put("proxyPort", "80");       // prop.put("proxyPort", "80"); 
      // prop.put("java.protocol.handler.pkgs","HTTPClient");       // prop.put("java.protocol.handler.pkgs","HTTPClient");
      fileChooser=null;       fileChooser=null;download=null;
     if(!runningAsApplet)      if(!runningAsApplet)
     {      {
       Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();        Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
       Point p=new Point((screenSize.width-300)/2,(screenSize.height-180)/2);        Point p=new Point((screenSize.width-700)/2,(screenSize.height-80)/2);
       JFrame testFrame=new JFrame();        JFrame testFrame=new JFrame();
       testFrame.setTitle("Archimedes Applet");        testFrame.setTitle("Archimedes Applet");
       testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        testFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       testFrame.getContentPane().add(this);        testFrame.getContentPane().add(this);
       testFrame.setSize(300,180);        testFrame.setSize(300,80);
       testFrame.setLocation(p);        testFrame.setLocation(p);
       testFrame.setVisible(true);        testFrame.setVisible(true);
       Console console = new Console(testFrame);        Console console = new Console(testFrame);
Line 135  public class Upload extends JApplet impl Line 132  public class Upload extends JApplet impl
       // proxy.setSelected(false);        // proxy.setSelected(false);
     }      }
   
       if (e.getActionCommand().equals("Download"))
       {
   
         if (downloadChooser == null)
         {
           downloadChooser = new JFileChooser();
           downloadChooser.setFileSelectionMode(fileChooser.FILES_AND_DIRECTORIES);
           downloadChooser.setFileFilter(new XMLFilter());
           downloadChooser.setDialogType(JFileChooser.SAVE_DIALOG);
           downloadChooser.addActionListener(new ActionListener()
           {
             public void actionPerformed(ActionEvent e2)
             {
               System.out.println(e2.getActionCommand());
               if (!e2.getActionCommand().toString().equals("ApproveSelection")) return;
               // {
   
        Thread thread = new Thread()
        {
           public void run()
           {
                  if(runningAsApplet)
                   set();
               UploadInfo dialog = new UploadInfo();
           
               File startFile=downloadChooser.getSelectedFile();
               dialog.thread=Thread.currentThread();
               //System.out.println("Called run with " + fileChooser.getSelectedFile());
               dialog.setTitle("Download Status Window");
               dialog.setSize(400, 175);
               dialog.setLocation(new java.awt.Point(150, 100));
             
                 long time = System.currentTimeMillis();
                 try 
                 {
                   Connection conGet = null;
                   if(!runningAsApplet)
                   conGet=new Connection( new URL("http://core.rz-berlin.mpg.de/edoctest/oi.epl"));
                   else
                   conGet=new Connection( new URL(url+"/oi.epl"));
                   
                   conGet.ses=ses;
                   conGet.dialog=dialog;
                   Bundle bundle = bundleRef;
                   int fileCount = bundle.documents.size();
                   new File(startFile.getAbsolutePath()+"/images").mkdirs();
                   File indexFile = new File(startFile.getAbsolutePath()+"/index.xml");
                   if(indexFile.exists())
                   bundle = getBundle(indexFile);
                   else
                   bundleRef.exportToXMLDownload(new File(startFile.getAbsolutePath()+"/index.xml"),startFile);
       
                   boolean update = (bundle != bundleRef);
                   // System.out.println("update "+update);
                   Vector docs = new Vector(); Bundle.Document refDoc = null; Vector list = new Vector();
                   if(update)
                   for(int k = 0;k <fileCount; ++k)
                   {
                         Bundle.Document doc = (Bundle.Document)bundleRef.documents.elementAt(k);
                         if((refDoc=(Bundle.Document)bundle.docs.get(new Integer(doc.docID)))!=null) 
                         {
                           if(checkForFileDownloaded(startFile.getAbsolutePath(),refDoc,doc))
                           {
                             if(!doc.downloadAgain)
                             list.addElement(doc.fileName);
                             docs.addElement(doc);//empty
                           } 
                          } else docs.addElement(doc);
                     }
                    if(!update)
                    docs=bundleRef.documents;
                   System.out.println(docs.size());
                   fileCount=docs.size();boolean keepAllFiles=false,newVersionforAll=false;
                   for(int i=0;i< fileCount;++i)
                   {
                     Bundle.Document doc=(Bundle.Document)docs.get(i);
                     
                     if(update&&(refDoc=(Bundle.Document)bundle.docs.get(new Integer(doc.docID)))!=null&&!doc.downloadAgain) 
                     {
                        System.out.println(refDoc+" "+doc.fileName);
   
                         if(!newVersionforAll&&!keepAllFiles)
                         {
                           Object[] options = new Object[] { "Cancel","Replace existing files", "Keep existing files" }; 
                           Object[] options2 = new Object[] { "Cancel","Replace existing file", "Keep existing file" }; 
                 
                           int option =  (list.size()>1) ? showDialog("Warning : several files  exist on the client \n Press show list to see the list! \n What do you want to do?", "several Files exist!", options,list):showDialog("Warning :  file "+refDoc.fileName+" exists on the client \n What do you want to do?", " File "+doc.fileName+" exists!", options2);
                 ;
                           if(option == 0) break;// mode = "old";
                         if(option == 1) 
                         { 
                           mode ="old";
                           newVersionforAll = true;
                           keepAllFiles = false;
                         }
                         if(option == 2) 
                         {  
                           count++;
                           System.out.println("Heh Document exists!"+ doc);
                           System.out.println("Skipping");
                           newVersionforAll = false;
                           keepAllFiles = true;
                           //continue;
                         }  
                       }
                 if(keepAllFiles) 
                 {
                   if(!doc.downloadAgain)
                   continue;
                 }
                 }// to bundle if
                 else
                 if(update) 
                 {
                    bundle.docs.put(new Integer(doc.docID),doc);
                    bundle.documents.addElement(doc);
                    bundle.docsLocator.put(doc.locator,doc); 
                 }   
                     if(doc.fileLink=="") continue;
                     System.out.println(doc.title);
                     conGet.url=new URL(doc.fileLink);
                     conGet.get();
                   
                     writeChunked(conGet,new File(startFile.getAbsolutePath()+"/images/"+doc.fileName),i+1, fileCount,doc.size, dialog);
                     String md5 =getMD5(conGet.md);
                     if(md5.equals(doc.md5cs)) System.out.println("download sucess");
                     else 
                      {
                        System.out.println(" md5 "+md5 +" "+doc.md5cs+ " "+doc.fileName);
                       break;
                      }
                      
                       if(debug)
                       System.out.println(" md5 "+md5 +" "+doc.md5cs+ " "+doc.fileName);
               
                   }
                 // close connection
                 conGet.socket.close();
                 dialog.setVisible(false);
                 long time2 =System.currentTimeMillis();
                  showDialog("Finished download of " + fileCount + " files in " + ((time2 - time) / 1000) + " seconds", "Finished Download");
                 if(update)
                 bundle.exportToXMLDownload(new File(startFile.getAbsolutePath()+"/index.xml"),startFile);
                 System.out.println("Time for download needed "+(time2-time));
     
                 } catch(Exception e5) 
                 {  
                     dialog.setVisible(false);
                     ByteArrayOutputStream b = new ByteArrayOutputStream();
                     PrintStream stream = new PrintStream(b);
                     e5.printStackTrace(stream);
                     //connections.remove(startFile.getAbsolutePath());
                     showErrorDialog(b.toString(), "Download failed");
                     }      
                  catch(Error err)
                 {
                    
                    showErrorDialog(err.toString(), "Download failed");
                   System.out.println("Error caught "+ err);
                 }
             }
        };
        thread.start();
       }
      });
      }
      downloadChooser.showDialog(new JFrame()," Download ");
    } 
     if (e.getActionCommand().equals("Upload"))      if (e.getActionCommand().equals("Upload"))
     {      {
   
Line 380  public class Upload extends JApplet impl Line 545  public class Upload extends JApplet impl
       conPost.post(file,"new",doc.docID+"",doc.title,doc.locator,doc.comment);        conPost.post(file,"new",doc.docID+"",doc.title,doc.locator,doc.comment);
       
     // conPost.post(new File("./test2.jpg"),picture.elementAt(i).toString(),artist.elementAt(i).toString(),source.elementAt(i).toString());      // conPost.post(new File("./test2.jpg"),picture.elementAt(i).toString(),artist.elementAt(i).toString(),source.elementAt(i).toString());
      System.out.println(getMD5(md));       System.out.println(getMD5(conPost.md));
      dialog.progress.setValue(100);       dialog.progress.setValue(100);
      count++;       count++;
     return count;      return count;
Line 395  public class Upload extends JApplet impl Line 560  public class Upload extends JApplet impl
     System.out.println(path);       System.out.println(path); 
     mode = "new";      mode = "new";
     boolean newVersionforAll = false, keepAllFiles = false;       boolean newVersionforAll = false, keepAllFiles = false; 
     Vector list=new Vector();      Vector list=new Vector();Vector docs=new Vector();Bundle.Document refDoc=null;
     for(int k=0;k<fileCount;++k)      for(int k=0;k<fileCount;++k)
     {      {
        Bundle.Document doc = (Bundle.Document)bundle.documents.elementAt(k);         Bundle.Document doc = (Bundle.Document)bundle.documents.elementAt(k);
        if(bundleRef.docsLocator.get(doc.locator)!=null)          if((refDoc=(Bundle.Document)bundleRef.docsLocator.get(doc.locator))!=null) 
          {
            if(checkForNewFile(path,doc,refDoc))
            {
        list.addElement(doc.fileName);         list.addElement(doc.fileName);
              docs.addElement(doc);
            }
          } else docs.addElement(doc);
     }      }
   
     for(int k=0;k<fileCount;++k)      for(int k=0;k<docs.size();++k)
     {      {
       Bundle.Document doc = (Bundle.Document)bundle.documents.elementAt(k);        Bundle.Document doc = (Bundle.Document)docs.elementAt(k);
             
       String response = "";        String response = "";
       dialog.title.setText("Uploading " + path+doc.fileName);        dialog.title.setText("Uploading " + path+doc.fileName);
Line 419  public class Upload extends JApplet impl Line 590  public class Upload extends JApplet impl
       dialog.repaint();        dialog.repaint();
       else        else
       dialog.show();        dialog.show();
         
       if(bundleRef.docsLocator.get(doc.locator)!=null)         if(bundleRef.docsLocator.get(doc.locator)!=null) 
       {        {
         if(!newVersionforAll&&!keepAllFiles)          if(!newVersionforAll&&!keepAllFiles)
Line 446  public class Upload extends JApplet impl Line 616  public class Upload extends JApplet impl
            continue;             continue;
          }             }  
       }        }
       Bundle.Document refDoc= (Bundle.Document) bundleRef.docsLocator.get(doc.locator);        refDoc= (Bundle.Document) bundleRef.docsLocator.get(doc.locator);
       doc.docID=refDoc.docID;        doc.docID=refDoc.docID;
       if(keepAllFiles)        if(keepAllFiles)
       {        {
Line 468  public class Upload extends JApplet impl Line 638  public class Upload extends JApplet impl
       conPost.ses=ses;        conPost.ses=ses;
       conPost.dialog=dialog;        conPost.dialog=dialog;
       conPost.post(path,doc,mode);        conPost.post(path,doc,mode);
       String md5=getMD5(md);        String md5=getMD5(conPost.md);
       System.out.println("MD5 is equal ?"+doc.md5cs.equals(md5)+" doc_md5 "+doc.md5cs+" md5 "+md5);        System.out.println("MD5 is equal ?"+doc.md5cs.equals(md5)+" doc_md5 "+doc.md5cs+" md5 "+md5);
       if(!doc.md5cs.equals(md5))        if(!doc.md5cs.equals(md5))
       {        {
Line 483  public class Upload extends JApplet impl Line 653  public class Upload extends JApplet impl
             conPost.ses=ses;              conPost.ses=ses;
             conPost.dialog=dialog;              conPost.dialog=dialog;
             conPost.post(path,doc,mode);                    conPost.post(path,doc,mode);      
             md5=getMD5(md);              md5=getMD5(conPost.md);
               if(!doc.md5cs.equals(md5)) showDialog("Transfer failed","Transfer failed again! ");
          }           }
       }      // System.out.println(getMD5(md));        }      // System.out.println(getMD5(md));
       dialog.progress.setValue(100);        dialog.progress.setValue(100);
       count++;        count++;
      }       }
        bundle.exportToXML(new File(path+"/temp.xml"));
      return count;       return count;
   }    }
     
Line 525  public class Upload extends JApplet impl Line 697  public class Upload extends JApplet impl
   
     return sb.toString();      return sb.toString();
   }    }
     public static boolean checkForNewFile(String path,Bundle.Document doc,Bundle.Document refDoc) throws Exception
     {
        String name = doc.fileLink.trim().startsWith("file://") ?doc.fileLink.trim().substring(7):doc.fileLink.trim();
        //System.out.println(name);
       boolean isNewFile=false;
        String filePath = name.startsWith("/") ? name:path+name;
        File file = new File(filePath);
        if(!file.exists()) 
        {
         
         showErrorDialog("Warning \n"+filePath +" does not exist !","Warning file does not exist !");
         return false;
        }
        if(file.isDirectory()) return false;
        FileInputStream f=new FileInputStream( filePath);
        int length=f.available();
        if(length!=refDoc.size) isNewFile=true;
         else
         {
            
             //new File(filePath).setLastModified(System.currentTimeMillis()-690000000L);
            Date actualTime = new Date(new File(filePath).lastModified());
            Date modified = new Date(doc.modified);//new File(filePath).lastModified());
           // System.out.println("actual Date "+actualTime);
           // System.out.println("Date file modified "+modified);
           // System.out.println("Time difference in minutes "+((actualTime.getTime()-modified.getTime())/60000L));
            // if file has been modified longer than 10 hours do not compare md5 --> file is not newer
            if(actualTime.getTime()==modified.getTime()) 
            {
             f.close();
             return false; 
            }
           
            MessageDigest md = MessageDigest.getInstance("MD5");
           byte[] b=new byte[512000];
           int   readCount =0;
           while (readCount < length)
           {
             if (readCount + b.length > length)
               f.read(b, 0, length - readCount); //  mout.flush();
             else
               f.read(b);
             if (readCount + b.length > length)
             {
               md.update(b, 0, length - readCount);
             }
             else
            {
               md.update(b, 0, b.length);
            }
           readCount += b.length;
           }
        isNewFile = !getMD5(md).equals(refDoc.md5cs);
        
        }
         // close file
         f.close();
      if(isNewFile)
        System.out.println(name+" "+refDoc.fileName);
    //  System.out.println("is new file ? "+isNewFile+" length is equal ?"+(length==refDoc.size));
      return isNewFile;
      }     
     public static boolean checkForFileDownloaded(String path,Bundle.Document doc,Bundle.Document refDoc) throws Exception
     {
        String name = doc.fileLink.trim().startsWith("file://") ?doc.fileLink.trim().substring(7):doc.fileLink.trim();
        //System.out.println(name);
        boolean isNewFile=false;
        String filePath = name.startsWith("/") ? name:path+name;
        File file = new File(filePath);
        if(!file.exists()) 
        {
          refDoc.downloadAgain = true;
          return true;
        }
        if(file.isDirectory()) return false;
         FileInputStream f=new FileInputStream( filePath);
        int length=f.available();
        if(length!=refDoc.size) 
        {
           // System.out.println(doc.fileName+" "+refDoc.fileName+" "+doc.size+" "
          // +refDoc.size+" "+length);
          refDoc.downloadAgain = doc.size>length;
          isNewFile = true;
        }
        else
        {
          isNewFile = !doc.md5cs.equals(refDoc.md5cs);
        }
       
      f.close();
      if(isNewFile)
        System.out.println(name+" "+refDoc.fileName);
    //  System.out.println("is new file ? "+isNewFile+" length is equal ?"+(length==refDoc.size));
      
      return isNewFile;
      }     
   
   public static String convertUml(String newName)    public static String convertUml(String newName)
   {    {
Line 620  public class Upload extends JApplet impl Line 888  public class Upload extends JApplet impl
     if(fileList==null)      if(fileList==null)
     list= new JList(new String[]{"click","here","test","bla","world","hello"});      list= new JList(new String[]{"click","here","test","bla","world","hello"});
     else list = new JList(fileList);      else list = new JList(fileList);
     
     JScrollPane scpane = new JScrollPane(list);      JScrollPane scpane = new JScrollPane(list);
     scpane.setPreferredSize(new Dimension(150,150));      scpane.setPreferredSize(new Dimension(150,150));
           
Line 829  public class Upload extends JApplet impl Line 1098  public class Upload extends JApplet impl
     // System.out.println(sb);      // System.out.println(sb);
     return sb;      return sb;
   }    }
     public static void writeChunked(Connection conTest,File f,int count,int fileCount,int fileSize,UploadInfo dialog) throws Exception
     {
       InputStream r= conTest.in;
       FileOutputStream file_out = new  FileOutputStream(f);
       BufferedOutputStream fout = new BufferedOutputStream(file_out);
       int c,countC=0,limit=conTest.in.available();
       // r.skip(211);
       String response = conTest.getResponseMessage();
       String lowerCase= response.toLowerCase();
       int index =lowerCase.indexOf("charset");
       int index2 =lowerCase.indexOf("=",index);
       int index3 =lowerCase.indexOf("\r",index2);
       String charset=(index>0) ? response.substring(index2+1,index3):"";
       charset="";//charset.toUpperCase();
       System.err.println(response);
       dialog.title.setText("Downloading to " + f.toString());
       dialog.progress.setValue(0);
        MessageDigest md =conTest.md;
        md.reset();
       String fileName = f.getName()+ " " + ((fileSize > 1000000) ? (fileSize / 1048576) + " MByte" : fileSize+ " Bytes");
         dialog.file.setText(fileName);
         dialog.status.setText(count + " of " + fileCount + ((fileCount > 1) ? " files" : " file"));
         //dialog.pack();
         //dialog.validate();
         if (dialog.isVisible())
         dialog.repaint();
         else
         dialog.show();
     
       if(lowerCase.indexOf("chunked")<0)
       {
         while(r.available()==0); 
         System.err.println(r.available());
         while ((c = r.read()) != -1) 
         {
           byte b=(byte)c;
           fout.write(b);             
           //md.update(b, 0, b.length);
           if(debug)
           System.out.print((char)c);
         }
       /* 
        if(charset!="")
         fout.write(local.toString(charset));
         else
         fout.write(local.toString());
         */
         //if(debug)
        // System.out.print(sb);
         //return sb;
       }
        StringBuffer sb = new StringBuffer(); 
       // read chunk size
       while ((c = r.read()) != -1) 
       {
         ++countC;
         char ch=(char)c;
         
         if(Character.digit(ch, 16) != -1)
         sb.append((char)c);
         if(ch=='\r')
         {
           ch=(char)r.read();
           if( ch=='\n') 
           break;
         }
          //System.out.print((char)c);
       }   
       int bufSize=Integer.parseInt(sb.toString().trim(), 16),newBufSize=0;
       
       System.err.println("chunk size "+Integer.parseInt(sb.toString().trim(), 16)+" bytes"+" limit "+limit);
       // sb.append((char)r.read());
       // sb.append((char)r.read());
       sb = new StringBuffer();//.delete(0,sb.length());
       byte[] b=new byte[bufSize];
       countC=0;int size = 0;
       StringBuffer localBuff=new StringBuffer();
       while (true) 
       {
         // sb.append(" new  Chunk "+r.available()+" \r\n ");
         int  readCount = 0;
         int available  = 0;
         int readSize    = b.length; int loop=0;
         while (readCount < bufSize)
         {
           available=r.available();
   
           if(available>=bufSize)
           readSize=bufSize;
           else
           readSize=available;
   
         if(readCount + readSize > bufSize)
         {
            readSize = r.read(b, readCount, bufSize - readCount); 
         }
         else
         {
           readSize = r.read(b,readCount,readSize);
         }
         if(loop>=60) 
         {
           loop = 0;
           conTest.socket.close();
           conTest.reconnect();
           conTest.get();
           r= conTest.in;
           file_out = new  FileOutputStream(f);
           fout = new BufferedOutputStream(file_out);
           countC=0;size=0;readCount= 0;conTest.md.reset();
           response = conTest.getResponseMessage();
           System.out.println(response);
           while ((c = r.read()) != -1) 
           {
             ++countC;
             char ch=(char)c;
             
             if(Character.digit(ch, 16) != -1)
             sb.append((char)c);
             if(ch=='\r')
             {
               ch=(char)r.read();
               if( ch=='\n') 
               break;
             }
             // System.out.print((char)c);
           }   
          bufSize=Integer.parseInt(sb.toString().trim(), 16);
        }
         //throw new Error("Connection timed out");
         if(readSize==0) 
         {
           long time = System.currentTimeMillis();
           while(System.currentTimeMillis()-time<100);
         } else loop=0;
         
       //if(debug)
      // System.out.println(++loop+" read "+readCount+" bytes"+" readSize "+readSize);
       readCount+=readSize;
       
     }
         
         //while(r.available()<bufSize); // critical if connection closed
       //  r.read(b,0,bufSize); 
         //System.err.println(r.available());
         char ch2=(char)r.read();
        // if(ch2=='\r') System.out.print("CR");
         ch2=(char)r.read();
        // if(ch2=='\n') System.out.println("LF");
        // if(debug)
        // System.out.println(new String(b,0,bufSize));
         while ( (c = r.read()) != -1) 
         {
           //      ++countC;
           char ch=(char)c;
           //System.err.println("read lf "+(ch=='\r')+" or cr "+( ch=='\n')+" "+(Character.digit(ch, 16) == -1));
           //if((ch!='\r')&&( ch!='\n')) System.err.println("read ch "+" "+ch+" "+Character.isSpace(ch));
          // System.out.print(ch);
           if(Character.digit(ch, 16) != -1)
           localBuff.append(ch);
           if(ch=='\r')
           {
             ch=(char)r.read();
             if( ch=='\n') 
             break;
           }
         }
         if(localBuff.length()>0)
         {
           // System.err.println("new chunk size "+Integer.parseInt(localBuff.toString().trim(), 16)+" bytes");
           // System.err.println((char)r.read());
           newBufSize=Integer.parseInt(localBuff.toString().trim(), 16);
           //if(bufSize==3041) bufSize=3040;
           if(debug)
          System.out.println("chunk size "+Integer.parseInt(localBuff.toString().trim(), 16)+" "+size);
     
           //localBuff.delete(0,localBuff.length());
            localBuff=new StringBuffer();
         } // else bufSize=0;
          if((char)b[bufSize-1]=='\n')
       {
           if(debug)
           System.out.println("LF found "+((char)b[bufSize-1]=='\n'));
           if(newBufSize==0) bufSize=bufSize-1;
           
       }
        fout.write(b,0,bufSize);
        md.update(b, 0, bufSize);
        size += bufSize;
        bufSize=newBufSize;
        dialog.progress.setValue((int) (((double) size / (double) fileSize) * 100.0));     
          ++countC;
        if(bufSize==0)
         break;
         // System.err.println(" in  Chunk "+bufSize+"   buffers used "+(countC)+" \r\n ");
         // // System.out.print((char)c);
       }
       // System.out.println(sb);
       fout.flush();
       fout.close();
     
       file_out.close();
       //return sb;
     }
   
   public static Hashtable getMetaData(String url)     public static Hashtable getMetaData(String url) 
   {    {
     Hashtable data=new Hashtable();      Hashtable data=new Hashtable();
Line 894  public class Upload extends JApplet impl Line 1368  public class Upload extends JApplet impl
        {         {
           // read XML Metadata from a file            // read XML Metadata from a file
           FileReader r=new FileReader(xmlFile);            FileReader r=new FileReader(xmlFile);
             BufferedReader buffr = new BufferedReader(r);
           StringBuffer sb=new StringBuffer();            StringBuffer sb=new StringBuffer();
           int c=0;            int c=0;
           while ((c = r.read()) != -1)             while ((c = buffr.read()) != -1) 
           {            {
             char ch=(char)c;              char ch=(char)c;
             sb.append(ch);              sb.append(ch);
Line 971  public class Upload extends JApplet impl Line 1446  public class Upload extends JApplet impl
       //addToBundle(bundle,sb);        //addToBundle(bundle,sb);
       // System.out.println(sb.toString());        // System.out.println(sb.toString());
       // System.exit(0);        // System.exit(0);
         conTest.socket.close();
     } catch(Exception e) {e.printStackTrace();}       } catch(Exception e) {e.printStackTrace();} 
     return bundle;      return bundle;
   }    }
Line 1146  public class Upload extends JApplet impl Line 1621  public class Upload extends JApplet impl
          System.out.println(Bundle.genresId.get(Bundle.genVec.get(i)));           System.out.println(Bundle.genresId.get(Bundle.genVec.get(i)));
         //System.out.println( Bundle.genres);          //System.out.println( Bundle.genres);
        }          } 
        conTest.socket.close();
     } catch(Exception e) {e.printStackTrace();}       } catch(Exception e) {e.printStackTrace();} 
   }    }
  public static String  getGenreList(StringBuffer sb)   public static String  getGenreList(StringBuffer sb)
Line 1309  public class Upload extends JApplet impl Line 1785  public class Upload extends JApplet impl
     String ses="";      String ses="";
     HttpURLConnection con;      HttpURLConnection con;
     UploadInfo dialog = new UploadInfo();      UploadInfo dialog = new UploadInfo();
       MessageDigest md ;
   
     public Connection(URL url) throws Exception      public Connection(URL url) throws Exception
     {      {
       Properties prop = System.getProperties();        Properties prop = System.getProperties();
Line 1344  public class Upload extends JApplet impl Line 1822  public class Upload extends JApplet impl
       in = new BufferedInputStream(socket.getInputStream(),2);        in = new BufferedInputStream(socket.getInputStream(),2);
       out = new PrintStream(new BufferedOutputStream(socket.getOutputStream()),true);        out = new PrintStream(new BufferedOutputStream(socket.getOutputStream()),true);
       this.url = url;        this.url = url;
         try 
         {
            md = MessageDigest.getInstance("MD5");
         
         } catch(Exception e) { e.printStackTrace();}
   
     }      }
    public String getSessionID(String data)      public String getSessionID(String data) 
    {     {
Line 1518  public class Upload extends JApplet impl Line 2002  public class Upload extends JApplet impl
      System.out.println(sb);       System.out.println(sb);
      if(sb.length()>0)       if(sb.length()>0)
      addToBundle(bundleRef,sb);       addToBundle(bundleRef,sb);
         try        // updating document with edoc Data
         {  
             
           Bundle.Document newDoc =(Bundle.Document) bundleRef.docsLocator.get(doc.locator);            Bundle.Document newDoc =(Bundle.Document) bundleRef.docsLocator.get(doc.locator);
           doc.md5cs=newDoc.md5cs;            doc.md5cs=newDoc.md5cs;
           doc.size=newDoc.size;            doc.size=newDoc.size;
Line 1528  public class Upload extends JApplet impl Line 2010  public class Upload extends JApplet impl
           doc.docID=newDoc.docID;            doc.docID=newDoc.docID;
           doc.ver=newDoc.ver;            doc.ver=newDoc.ver;
           doc.fileVer=newDoc.fileVer;            doc.fileVer=newDoc.fileVer;
           bundle.exportToXML(new File("./meta.xml"));            doc.modified = new File(filePath).lastModified();
         } catch(Exception e7) { e7.printStackTrace();}         
     }      }
       
     public void sendFile(FileInputStream f,PrintStream out) throws Exception      public void sendFile(FileInputStream f,PrintStream out) throws Exception
Line 1537  public class Upload extends JApplet impl Line 2019  public class Upload extends JApplet impl
         int length=f.available();          int length=f.available();
         md.reset();          md.reset();
         dialog.progress.setValue(0);          dialog.progress.setValue(0);
         byte[] b=new byte[512];          byte[] b=new byte[16204];
         int   readCount =0;          int   readCount =0;
         while (readCount < length)          while (readCount < length)
         {          {
Line 1570  public class Upload extends JApplet impl Line 2052  public class Upload extends JApplet impl
     {      {
       try        try
       {        {
         // System.out.println("Yeah i called connect");           // System.out.println("Yeah i called get with "+url );
         //  socket = new Socket((pHost != null) ? pHost : url.getHost(), (pHost != null) ? pPort : url.getPort());          //  socket = new Socket((pHost != null) ? pHost : url.getHost(), (pHost != null) ? pPort : url.getPort());
         // socket.setTcpNoDelay(true);          // socket.setTcpNoDelay(true);
         in = new BufferedInputStream(socket.getInputStream());          in = new BufferedInputStream(socket.getInputStream());

Removed from v.1.2  
changed lines
  Added in v.1.4


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>