|
42 | 42 | import java.util.logging.Logger;
|
43 | 43 |
|
44 | 44 | import be.panako.strategy.Strategy;
|
45 |
| -import be.panako.util.Config; |
46 |
| -import be.panako.util.Key; |
47 |
| -import be.panako.util.StopWatch; |
48 |
| -import be.panako.util.TimeUnit; |
| 45 | +import be.panako.util.*; |
49 | 46 |
|
50 | 47 | /**
|
51 | 48 | * Store audio fingerptings in the storage.
|
@@ -116,49 +113,31 @@ public StoreTask(File file,int taskID,int totalTasks){
|
116 | 113 |
|
117 | 114 | @Override
|
118 | 115 | public void run() {
|
119 |
| - |
120 | 116 | StopWatch w = new StopWatch();
|
121 |
| - if(checkFile(file)){ |
122 |
| - |
123 |
| - Strategy strategy = Strategy.getInstance(); |
124 |
| - |
125 |
| - boolean isDouble = false; |
126 |
| - if(Config.getBoolean(Key.CHECK_DUPLICATE_FILE_NAMES) ){ |
127 |
| - isDouble = strategy.hasResource(file.getAbsolutePath()); |
128 |
| - } |
| 117 | + Strategy strategy = Strategy.getInstance(); |
129 | 118 |
|
130 |
| - String message=null; |
131 |
| - if(isDouble){ |
132 |
| - message = String.format("%d/%d;%s;%s",taskID,totalTasks,file.getName(),"Skipped: resource already stored;"); |
133 |
| - }else{ |
134 |
| - double durationInSeconds = strategy.store(file.getAbsolutePath(), file.getName()); |
135 |
| - double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS); |
136 |
| - String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds)); |
137 |
| - String cpuTimeDuration = w.formattedToString(); |
138 |
| - double timeRatio = durationInSeconds/cpuSecondsPassed; |
139 |
| - message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio); |
140 |
| - } |
141 |
| - LOG.info(message); |
142 |
| - System.out.println(message); |
| 119 | + boolean isDouble = false; |
| 120 | + if(Config.getBoolean(Key.CHECK_DUPLICATE_FILE_NAMES) ){ |
| 121 | + isDouble = strategy.hasResource(file.getAbsolutePath()); |
143 | 122 | }
|
144 |
| - } |
145 |
| - |
146 |
| - private boolean checkFile(File file){ |
147 |
| - boolean fileOk = false; |
148 |
| - |
149 |
| - //file must be smaller than a configured number of bytes |
150 |
| - long maxFileSize = Config.getInt(Key.MAX_FILE_SIZE); |
151 |
| - //from megabytes to bytes |
152 |
| - maxFileSize = maxFileSize * 1024 * 1024; |
153 |
| - if(file.length() != 0 && file.length() < maxFileSize ){ |
154 |
| - fileOk = true; |
| 123 | + |
| 124 | + String message=null; |
| 125 | + if(isDouble){ |
| 126 | + message = String.format("%d/%d;%s;%s",taskID,totalTasks,file.getName(),"Skipped: resource already stored;"); |
155 | 127 | }else{
|
156 |
| - String message = "Could not process " + file.getName() + " it has an unacceptable file size.\n\tFile is " + file.length() + " bytes. \n\tShould be more than zero and smaller than " + Config.getInt(Key.MAX_FILE_SIZE) + " bytes )."; |
157 |
| - LOG.warning(message); |
158 |
| - System.out.println(message); |
| 128 | + double durationInSeconds = strategy.store(file.getAbsolutePath(), file.getName()); |
| 129 | + double cpuSecondsPassed = w.timePassed(TimeUnit.SECONDS); |
| 130 | + String audioDuration = StopWatch.toTime("", (int) Math.round(durationInSeconds)); |
| 131 | + String cpuTimeDuration = w.formattedToString(); |
| 132 | + double timeRatio = durationInSeconds/cpuSecondsPassed; |
| 133 | + message = String.format("%d/%d;%s;%s;%s;%.2f",taskID,totalTasks,file.getName(),audioDuration,cpuTimeDuration,timeRatio); |
159 | 134 | }
|
160 |
| - return fileOk; |
| 135 | + LOG.info(message); |
| 136 | + System.out.println(message); |
| 137 | + |
161 | 138 | }
|
| 139 | + |
| 140 | + |
162 | 141 | }
|
163 | 142 |
|
164 | 143 |
|
|
0 commit comments