Create temp file from a given dataset This assumes 1) The dataset has at least 1 record 2) All records are of the same size
(String[][] data)
| 251 | * 2) All records are of the same size |
| 252 | */ |
| 253 | public static File createTempFile(String[][] data) throws IOException { |
| 254 | |
| 255 | File fp1 = File.createTempFile("test", "txt"); |
| 256 | PrintStream ps = new PrintStream(new FileOutputStream(fp1)); |
| 257 | |
| 258 | for(int i = 0; i < data.length ; i++) { |
| 259 | |
| 260 | // Building up string for each line |
| 261 | StringBuilder sb = new StringBuilder() ; |
| 262 | for(int j = 0 ; j < data[0].length ; j++) { |
| 263 | if (j != 0) { |
| 264 | sb.append("\t") ; |
| 265 | } |
| 266 | sb.append(data[i][j]) ; |
| 267 | } |
| 268 | |
| 269 | // Write the line to file |
| 270 | ps.println(sb.toString()); |
| 271 | } |
| 272 | |
| 273 | ps.close(); |
| 274 | return fp1 ; |
| 275 | } |
| 276 | |
| 277 | //a quick way to check for map equality as the map value returned by PigStorage has byte array |
| 278 | public static boolean mapEquals(Map<String, Object> expectedMap, Map<String, Object> convertedMap) { |
no test coverage detected