Convert the specified tuple list (with only integer fields) into a binary page file. The format of the output file will be as specified in HeapPage and HeapFile. @see HeapPage @see HeapFile @param tuples the tuples - a list of tuples, each represented by a list of integers that are the
(List<List<Integer>> tuples, File outFile, int npagebytes, int numFields)
| 33 | * @throws IOException if the temporary/output file can't be opened |
| 34 | */ |
| 35 | public static void convert(List<List<Integer>> tuples, File outFile, int npagebytes, int numFields) throws IOException { |
| 36 | File tempInput = File.createTempFile("tempTable", ".txt"); |
| 37 | tempInput.deleteOnExit(); |
| 38 | BufferedWriter bw = new BufferedWriter(new FileWriter(tempInput)); |
| 39 | for (List<Integer> tuple : tuples) { |
| 40 | int writtenFields = 0; |
| 41 | for (Integer field : tuple) { |
| 42 | writtenFields++; |
| 43 | if (writtenFields > numFields) { |
| 44 | throw new RuntimeException("Tuple has more than " + numFields + " fields: (" + |
| 45 | Utility.listToString(tuple) + ")"); |
| 46 | } |
| 47 | bw.write(String.valueOf(field)); |
| 48 | if (writtenFields < numFields) { |
| 49 | bw.write(','); |
| 50 | } |
| 51 | } |
| 52 | bw.write('\n'); |
| 53 | } |
| 54 | bw.close(); |
| 55 | convert(tempInput, outFile, npagebytes, numFields); |
| 56 | } |
| 57 | |
| 58 | public static void convert(File inFile, File outFile, int npagebytes, |
| 59 | int numFields) throws IOException { |