Advertisement
Guest User

Untitled

a guest
Sep 19th, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. package exiftool_test;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8. import java.io.OutputStreamWriter;
  9. import java.util.ArrayList;
  10. import java.util.List;
  11.  
  12. public class ExifProcess {
  13.  
  14. private ProcessBuilder exifProcessBuilder;
  15. private Process exifProcess;
  16. private List<String> cmd;
  17. private BufferedReader cmd_reader;
  18. private OutputStreamWriter cmd_writer;
  19. private File file;
  20. private String filePathName;
  21. private String fileDirectoryPathName;
  22. private String buffer;
  23. private int lastBackSlash = 0;
  24. private boolean daemon_mode;
  25.  
  26. private static final String PATH = "C:\Users\jhubsche\Desktop\DAM_project\ExifTool_tests";
  27. // test path file => C:UsersjhubscheDesktopDAM_projectExifTool_teststest3.avi
  28.  
  29. public ExifProcess(String completePath, boolean daemon_mode) throws FileNotFoundException, IOException, InterruptedException {
  30.  
  31. buffer = "";
  32. this.daemon_mode = daemon_mode;
  33.  
  34. //default arguments to command line/process; later, make methods in ExifProcess that change general modes
  35. //(i.e. scanAll, scanAllShort, scanAllNumeric, scanAllBinary, scanAllFormatted, scanSpecified (for tags), ScanAllSorted, etc.)
  36. cmd = new ArrayList<String>(1);
  37. cmd.add("C:\Windows\exiftool.exe");
  38.  
  39. if(daemon_mode) {
  40. //possible complications here, learn more about exif's daemon mode
  41. //and its possible ARGS file, and pipe output redirection from a process.
  42. cmd.add("-stay_open");
  43. cmd.add("True");
  44. cmd.add("-@");
  45. cmd.add("-");
  46. cmd.add("-a");
  47. cmd.add("-u");
  48. cmd.add("-S");
  49. cmd.add(completePath);
  50. }
  51.  
  52. else {
  53.  
  54. cmd.add("-a");
  55. cmd.add("-u");
  56. cmd.add("-S");
  57. cmd.add(completePath);
  58. }
  59.  
  60. //set directory path variable
  61. initializePathVars(completePath);
  62. file = new File(completePath);
  63.  
  64. if(file.isDirectory()) {
  65. //make method(s) that will check which files in the directory that weren't scanned by ExifTool,
  66. //and then scan those individually.They may use arrays (or ArrayLists, etc.) carrying their paths
  67. //and you can for loop (for each loop) through the paths, running ExifTool for each missed file.
  68. }
  69.  
  70. exifProcessStarter(file, cmd);
  71. }
  72.  
  73. private void exifProcessStarter(File file,List<String> params) throws IOException, InterruptedException {
  74.  
  75. exifProcessBuilder = new ProcessBuilder(cmd);
  76. exifProcess = exifProcessBuilder.start();
  77.  
  78. //Setup read/write streams to the new process.
  79. cmd_reader = new BufferedReader(new InputStreamReader(exifProcess.getInputStream()));
  80. cmd_writer = new OutputStreamWriter(exifProcess.getOutputStream());
  81.  
  82. /*if(daemon_mode) {
  83.  
  84. cmd_writer.write("-an");
  85. cmd_writer.write("-un");
  86. cmd_writer.write("-Sn");
  87. cmd_writer.write(file.getPath());
  88. cmd_writer.write("n");
  89. cmd_writer.write("-executen");
  90. cmd_writer.flush();
  91. //cmd.add("> foo.txt");
  92. }*/
  93.  
  94. readPrompt();
  95.  
  96. }
  97.  
  98. public void readPrompt() throws IOException, InterruptedException {
  99.  
  100. exifProcess.waitFor();
  101. while((buffer = cmd_reader.readLine()) != null) {
  102.  
  103. if(buffer == null || buffer == "")
  104. break;
  105.  
  106. System.out.println(buffer);
  107. }
  108. }
  109.  
  110. private void initializePathVars(String completePath) {
  111.  
  112. lastBackSlash = completePath.lastIndexOf("\");
  113. filePathName = completePath.substring(lastBackSlash + 1, completePath.length());
  114. fileDirectoryPathName = completePath.substring(0,lastBackSlash);
  115. }
  116.  
  117. public void setFileDirectoryPathName(String fileDirectoryPathName) {
  118.  
  119. this.fileDirectoryPathName = fileDirectoryPathName;
  120. }
  121.  
  122. public String getFileDirectoryPathName() {
  123.  
  124. return fileDirectoryPathName;
  125. }
  126.  
  127. public void setFilePathName(String filePathName) {
  128.  
  129. this.filePathName = filePathName;
  130. }
  131.  
  132. public boolean daemonModeON() throws IOException {
  133.  
  134. cmd_writer.write("-stay_open Truen");
  135. cmd_writer.write("-executen");
  136. cmd_writer.flush();
  137. return daemon_mode = true;
  138. }
  139.  
  140. public boolean daemonModeOFF() throws IOException {
  141. cmd_writer.write("-stay_open Falsen");
  142. return daemon_mode = false;
  143. }
  144.  
  145. public String getFilePathName() {
  146.  
  147. return filePathName;
  148. }
  149.  
  150. public void writeCommand(String line) throws IOException {
  151.  
  152. cmd_writer.write(line);
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement