Package v7db.files.mongodb

Examples of v7db.files.mongodb.V7File


  private void testSimpleScenario(byte[] fileData) throws IOException {

    // insert

    gridFS.addFile(fileData, "root", "test.dat", "text/plain");
    V7File file = gridFS.getFile("root", "test.dat");
    assertEquals("test.dat", file.getName());
    assertEquals("text/plain", file.getContentType());
    assertEquals(Arrays.toString(fileData), Arrays.toString(IOUtils
        .toByteArray(file.getInputStream())));
    assertEquals(fileData.length, file.getLength().intValue());
    assertEquals(1, file.getVersion());
    assertEquals("root", file.getParentId());

    V7File root = file.getParent();
    assertEquals("root", root.getId());
    List<V7File> files = root.getChildren();
    assertEquals(1, files.size());

    // update

    file.setContent("updated contents".getBytes(), "text/plain");
View Full Code Here


    testSimpleScenario(bytes);
  }

  public void testFolder() throws IOException {
    ObjectId folderId = gridFS.addFolder("root", "foolder");
    V7File folder = gridFS.getFile("root", "foolder");
    assertEquals("foolder", folder.getName());
    assertEquals(folderId, folder.getId());
    assertEquals(false, folder.hasContent());

    V7File file = folder.createChild("a file in there".getBytes(),
        "file.txt", "text/plain");
    assertEquals(folder.getId(), file.getParentId());
    V7File checkFile = gridFS.getFile("root", "foolder", "file.txt");
    assertEquals(file.getId(), checkFile.getId());
    assertEquals(folder.getId(), checkFile.getParentId());

  }
View Full Code Here

  public void testSimple() throws IOException {
    V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
    MkdirCommand.main(new String[] { "mkdir", "x", "123" });
    {
      V7File check = fs.getFile("x", "123");
      assertFalse(check.hasContent());
      assertEquals("[]", check.getChildren().toString());
    }
    MkdirCommand.main(new String[] { "mkdir", "x", "123/456" });
    {
      V7File check = fs.getFile("x", "123", "456");
      assertFalse(check.hasContent());
      assertEquals("[]", check.getChildren().toString());
    }
  }
View Full Code Here

    CopyCommand.main(new String[] { "copy", "-sha", sha.getDigest(), "x",
        "copy.txt" });

    V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
    V7File file = fs.getFile("x", "copy.txt");
    assertEquals("test", IOUtils.toString(file.getInputStream()));

  }
View Full Code Here

    fs.addFile("test".getBytes(), dir, "test.txt", "text/plain");

    CopyCommand.main(new String[] { "copy", "test", "folder/test.txt", "x",
        "copy.txt" });

    V7File file = fs.getFile("x", "copy.txt");
    assertEquals("test", IOUtils.toString(file.getInputStream()));
    assertEquals("text/plain", file.getContentType());
  }
View Full Code Here

    fs.addFile("test".getBytes(), dir, "test.txt", "text/plain");

    CopyCommand
        .main(new String[] { "copy", "test", "folder", "x", "copy" });

    V7File file = fs.getFile("x", "copy", "test.txt");
    assertEquals("test", IOUtils.toString(file.getInputStream()));
    assertEquals("text/plain", file.getContentType());
  }
View Full Code Here

    Properties props = new Properties();
    props.setProperty("acl.provider", aclProvider);
    AuthorisationProvider auth = AuthorisationProviderFactory
        .getAuthorisationProvider(props);

    V7File dummyFile = new V7File(null, new BasicDBObject(), null);

    assertFalse(auth.authoriseOpen(dummyFile, null));
    assertFalse(auth
        .authoriseOpen(dummyFile, AuthenticationToken.ANONYMOUS));
    assertFalse(auth.authoriseRead(dummyFile, null));
View Full Code Here

    String root = args[1];
    String path = args[2];
    String[] fullPath = ArrayUtils.add(StringUtils.split(path, '/'), 0,
        root);
    V7File file = fs.getFile(fullPath);
    if (file == null) {
      System.err.println("file not found");
      System.exit(1);
    }
    if (file.hasContent()) {
      System.out.format("    %10d %80s\n", file.getLength(), file
          .getName());
    }
    List<V7File> children = file.getChildren();
    Collections.sort(children, new Comparator<V7File>() {

      public int compare(V7File o1, V7File o2) {
        return o1.getName().compareTo(o2.getName());
      }
View Full Code Here

      ConflictException, NotAuthorizedException, BadRequestException {

    Resource existingChild = child(newName);
    if (existingChild == null) {

      V7File child = file.createChild(inputStream, newName, contentType);

      return new FileResource(child, factory);
    }
    if (existingChild instanceof FolderResource) {
      throw new ConflictException(existingChild,
View Full Code Here

  Resource createNew(String newName, ContentPointer content,
      String contentType) throws IOException, ConflictException {
    Resource existingChild = child(newName);
    if (existingChild == null) {

      V7File child = file.createChild(content, newName, contentType);

      return new FileResource(child, factory);
    }
    if (existingChild instanceof FolderResource) {
      throw new ConflictException(existingChild,
View Full Code Here

TOP

Related Classes of v7db.files.mongodb.V7File

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.