Advertisement
Guest User

Untitled

a guest
Sep 17th, 2014
502
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.37 KB | None | 0 0
  1.     public static void main(String[] args) throws Exception {
  2.         new Server().run();
  3.        
  4.         writeNew();
  5.         read2();
  6.  
  7.     }
  8.    
  9.     private static void writeNew() throws Exception {
  10.         FileInputStream in = new FileInputStream("C:/.pkx_v5/main_file_cachee.dat");
  11.         byte[] buffer = new byte[1024];
  12.         ObjectOutputStream o = new ObjectOutputStream(new FileOutputStream("C:/.pkx_v5/new.tar.gz"));
  13.        
  14.         int len = 0;
  15.         while (in.read(buffer) > 0) {
  16.             ++len;
  17.         }
  18.        
  19.         o.writeInt(len);
  20.        
  21.         in.close();
  22.         in = new FileInputStream("C:/.pkx_v5/main_file_cachee.dat");
  23.        
  24.         while (in.read(buffer) > 0) {
  25.             o.writeObject(buffer);
  26.         }
  27.        
  28.         o.close();
  29.         in.close();
  30.     }
  31.    
  32.     private static void read2() throws Exception {
  33.         FileInputStream in = new FileInputStream("C:/.pkx_v5/new.tar.gz");
  34.         ObjectInputStream obj = new ObjectInputStream(in);
  35.        
  36.         int line = obj.readInt();
  37.        
  38.         List<byte[]> bytes = new ArrayList<byte[]>();
  39.        
  40.         for (int i = 0; i < line; i++) {
  41.             bytes.add( (byte[]) obj.readObject());
  42.         }
  43.        
  44.         obj.close();
  45.        
  46.         byte[] finalArray = new byte[bytes.size() * 1024];
  47.         int lastFilled = 0;
  48.        
  49.         for (byte[] array : bytes) {
  50.             for (int i = 0; i < array.length; i++) {
  51.                 finalArray[lastFilled] = array[i];
  52.                 lastFilled++;
  53.             }
  54.         }
  55.        
  56.         FileOutputStream f = new FileOutputStream("C:/.pkx_v5/main_file_cache.dat");
  57.         f.write(finalArray);
  58.         f.close();
  59.        
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement