Repository where I mostly put random python scripts.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.6 KiB

  1. import java.io.BufferedWriter;
  2. import java.io.File;
  3. import java.io.FileWriter;
  4. import java.math.*;
  5. /**
  6. * Simple class to generate random data for
  7. * file IO tests.
  8. *
  9. * @author Jeffery Russell 1-31-19
  10. */
  11. public class DataCreator
  12. {
  13. /**
  14. * Generates an obscure random character
  15. * @return
  16. */
  17. private static char rndChar()
  18. {
  19. // or use Random or whatever
  20. int rnd = (int) (Math.random() * 52);
  21. char base = (rnd < 26) ? 'A' : 'a';
  22. return (char) (base + rnd % 26);
  23. }
  24. /**
  25. * Simple function to save contents to the disk
  26. *
  27. * @param s
  28. * @param fileName
  29. */
  30. private static void saveToDisk(String s, String fileName)
  31. {
  32. BufferedWriter writer;
  33. try
  34. {
  35. File file = new File(fileName);
  36. file.createNewFile();
  37. writer = new BufferedWriter(new FileWriter(file));
  38. writer.write(s);
  39. writer.flush();
  40. writer.close();
  41. }
  42. catch (Exception e)
  43. {
  44. e.printStackTrace();
  45. }
  46. }
  47. /**
  48. * Creates 5MB of random test data to use
  49. */
  50. public static void main(String[] arguments)
  51. {
  52. System.out.println("Creating Test Files");
  53. for(int i = 0; i < 100; i++)
  54. {
  55. //10k random characters for each file
  56. //each file is 10kb * 500 files, total size of 5MB
  57. String s = "";
  58. for(int j = 0; j < 1000000; j++)
  59. {
  60. s = s + rndChar();
  61. }
  62. saveToDisk(s, "./testData/" + i + ".txt");
  63. System.out.println(s);
  64. }
  65. }
  66. }