Advertisement
Guest User

Cutupper

a guest
Dec 7th, 2014
148
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.77 KB | None
  1. import java.io.BufferedReader;
  2. import java.io.BufferedWriter;
  3. import java.io.File;
  4. import java.io.FileReader;
  5. import java.io.FileWriter;
  6. import java.io.IOException;
  7. import java.util.Random;
  8. import java.util.StringTokenizer;
  9. import java.util.Vector;
  10.  
  11.  
  12. public class Cutupper {
  13.  
  14.     public static void main(String[] args) throws IOException
  15.     {
  16.         if(args.length!=2)
  17.         {
  18.             System.out.println("Please provide a path to a file which content"
  19.                     + "should be cut-up and an output path.");
  20.             System.exit(0);
  21.         }
  22.         /*
  23.          * PARSE INPUT FILE
  24.          */
  25.         File f = new File(args[0]);
  26.         FileReader fr = new FileReader(f);
  27.         BufferedReader br = new BufferedReader(fr);
  28.         String line = br.readLine();
  29.         String textBuffer = "";
  30.         while(line!=null)
  31.         {
  32.             textBuffer += line;
  33.             line = br.readLine();
  34.         }
  35.         br.close();
  36.        
  37.         /*
  38.          * TEILE AN KOMMAS UND SETZTE DIE TEILE ZUFAELLIG WIEDER ZUSAMMEN
  39.          */
  40.         Vector<String> parts = new Vector<String>();
  41.         StringTokenizer tokenizer = new StringTokenizer(textBuffer,",");
  42.         while(tokenizer.hasMoreTokens())
  43.         {
  44.             parts.add(tokenizer.nextToken()+",");
  45.         }
  46.         textBuffer = "";
  47.         Random rand = new Random();
  48.         while(parts.size()>0)
  49.         {
  50.             int index = rand.nextInt(parts.size());
  51.             textBuffer += parts.get(index);
  52.             parts.remove(index);
  53.         }
  54.        
  55.         /*
  56.          * TEILE AN PUNKTEN UND SETZTE ZUFAELLIG WIEDER ZUSAMMEN
  57.          */
  58.         tokenizer = new StringTokenizer(textBuffer,".");
  59.         while(tokenizer.hasMoreTokens())
  60.         {
  61.             parts.add(tokenizer.nextToken()+".");
  62.         }
  63.         File out = new File(args[1]);
  64.         FileWriter fw = new FileWriter(out);
  65.         BufferedWriter bw = new BufferedWriter(fw);
  66.         while(parts.size()>0)
  67.         {
  68.             int index = rand.nextInt(parts.size());
  69.             bw.write(parts.get(index));
  70.             parts.remove(index);
  71.         }
  72.         bw.close();
  73.     }
  74.  
  75. }
Advertisement
RAW Paste Data Copied
Advertisement