Encode the file using the BTreeFile's Insert method. @param tuples - list of tuples to add to the file @param hFile - the file to temporarily store the data as a heap file on disk @param bFile - the file on disk to back the resulting BTreeFile @param keyField - the index of the key field for this B
(List<List<Integer>> tuples, File hFile, File bFile, int keyField, int numFields)
| 32 | * @return the BTreeFile |
| 33 | */ |
| 34 | public static BTreeFile convert(List<List<Integer>> tuples, File hFile, |
| 35 | File bFile, int keyField, 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 | bw.close(); |
| 45 | throw new RuntimeException("Tuple has more than " + numFields + " fields: (" + |
| 46 | Utility.listToString(tuple) + ")"); |
| 47 | } |
| 48 | bw.write(String.valueOf(field)); |
| 49 | if (writtenFields < numFields) { |
| 50 | bw.write(','); |
| 51 | } |
| 52 | } |
| 53 | bw.write('\n'); |
| 54 | } |
| 55 | bw.close(); |
| 56 | return convert(tempInput, hFile, bFile, keyField, numFields); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Encode the file using the BTreeFile's Insert method. |
no test coverage detected