MCPcopy Create free account
hub / github.com/1345414527/MIT6.830 / createEmptyHeapFile

Method createEmptyHeapFile

src/java/simpledb/common/Utility.java:105–126  ·  view source on GitHub ↗

A utility method to create a new HeapFile with a single empty page, assuming the path does not already exist. If the path exists, the file will be overwritten. The new table will be added to the Catalog with the specified number of columns as IntFields.

(String path, int cols)

Source from the content-addressed store, hash-verified

103 * the specified number of columns as IntFields.
104 */
105 public static HeapFile createEmptyHeapFile(String path, int cols)
106 throws IOException {
107 File f = new File(path);
108 // touch the file
109 FileOutputStream fos = new FileOutputStream(f);
110 fos.write(new byte[0]);
111 fos.close();
112
113 HeapFile hf = openHeapFile(cols, f);
114 HeapPageId pid = new HeapPageId(hf.getId(), 0);
115
116 HeapPage page = null;
117 try {
118 page = new HeapPage(pid, HeapPage.createEmptyPageData());
119 } catch (IOException e) {
120 // this should never happen for an empty page; bail;
121 throw new RuntimeException("failed to create empty page in HeapFile");
122 }
123
124 hf.writePage(page);
125 return hf;
126 }
127
128 /** Opens a HeapFile and adds it to the catalog.
129 *

Callers 2

setUpMethod · 0.95
setupMethod · 0.95

Calls 5

openHeapFileMethod · 0.95
getIdMethod · 0.95
createEmptyPageDataMethod · 0.95
writePageMethod · 0.95
closeMethod · 0.65

Tested by 2

setUpMethod · 0.76
setupMethod · 0.76