Пример #1
0
  public OutputStream getOutput(String pathname, boolean append, int chunk_size)
      throws IOException {
    GridFile file = (GridFile) getFile(pathname, chunk_size);
    if (!file.createNewFile()) throw new IOException("creation of " + pathname + " failed");

    return new GridOutputStream(file, append, data, chunk_size);
  }
Пример #2
0
  public void testDeleteRemovesAllChunks() throws Exception {
    assertEquals(numberOfChunksInCache(), 0);
    assertEquals(numberOfMetadataEntries(), 0);

    writeToFile("delete.txt", "delete me", 100);

    GridFile file = (GridFile) fs.getFile("delete.txt");
    boolean deleted = file.delete();
    assertTrue(deleted);
    assertFalse(file.exists());
    assertEquals(numberOfChunksInCache(), 0);
    assertEquals(numberOfMetadataEntries(), 0);
  }
Пример #3
0
  public void testWriteAcrossMultipleChunksWithNonDefaultChunkSizeAfterFileIsExplicitlyCreated()
      throws Exception {
    GridFile file = (GridFile) fs.getFile("multipleChunks.txt", 20); // chunkSize = 20
    file.createNewFile();

    writeToFile(
        "multipleChunks.txt",
        "This text spans multiple chunks, because each chunk is only 20 bytes long.",
        10); // chunkSize = 10 (but it is ignored, because the file was already created with
    // chunkSize = 20

    String text = getContents("multipleChunks.txt");
    assertEquals(
        text, "This text spans multiple chunks, because each chunk is only 20 bytes long.");
  }
Пример #4
0
 GridInputStream(GridFile file, Cache<String, byte[]> cache, int chunk_size)
     throws FileNotFoundException {
   this.file = file;
   this.name = file.getPath();
   this.cache = cache;
   this.chunk_size = chunk_size;
 }
Пример #5
0
 public InputStream getInput(String pathname) throws FileNotFoundException {
   GridFile file = (GridFile) getFile(pathname);
   if (!file.exists()) throw new FileNotFoundException(pathname);
   return new GridInputStream(file, data, default_chunk_size);
 }
Пример #6
0
 public OutputStream getOutput(GridFile file) throws IOException {
   if (!file.createNewFile()) throw new IOException("creation of " + file + " failed");
   return new GridOutputStream(file, false, data, default_chunk_size);
 }
Пример #7
0
 private String getChunkKey(int chunkNumber) {
   return getChunkKey(file.getAbsolutePath(), chunkNumber);
 }
Пример #8
0
 public int getChunkSize() {
   return file.getChunkSize();
 }