Package v7db.files.mongodb

Examples of v7db.files.mongodb.V7GridFS


  protected void setUp() throws Exception {
    super.setUp();
    // the root folder
    prepareMockData("test.v7files.files",
        new BasicBSONObject("_id", "root"));
    gridFS = new V7GridFS(getMongo().getDB("test"));
  }
View Full Code Here


        .getDefaultProperties());

  }

  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

      assertEquals("[]", check.getChildren().toString());
    }
  }

  public void testExisting() throws IOException {
    V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
    fs.addFolder("x", "123");
    try {
      MkdirCommand.main(new String[] { "mkdir", "x", "123" });
      fail("should have croaked on existing directory");
    } catch (IOException e) {
View Full Code Here

        .getBytes()));

    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

    assertEquals("test", IOUtils.toString(file.getInputStream()));

  }

  public void testCopyFile() throws IOException {
    V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
    ObjectId dir = fs.addFolder("test", "folder");
    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

    assertEquals("test", IOUtils.toString(file.getInputStream()));
    assertEquals("text/plain", file.getContentType());
  }

  public void testCopyDirectory() throws IOException {
    V7GridFS fs = new V7GridFS(getMongo().getDB("test"));
    ObjectId dir = fs.addFolder("test", "folder");
    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

      System.err.println("List a file or directory:");
      System.err.println("  ls <root> <path>");
      System.exit(1);
    }

    V7GridFS fs = new V7GridFS(Configuration.getMongo().getDB(
        Configuration.getProperty("mongo.db")));

    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()) {
View Full Code Here

            + " is not a hex-encoded SHA-1 prefix");
        System.exit(1);
      }
    } else {

      V7GridFS fs = new V7GridFS(Configuration.getMongo().getDB(
          Configuration.getProperty("mongo.db")));

      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);
      }
      IOUtils.copy(file.getInputStream(), System.out);
View Full Code Here

    }

    DB db = Configuration.getMongo().getDB(
        Configuration.getProperty("mongo.db"));

    V7GridFS fs = new V7GridFS(db);

    if ("-sha".equals(args[1])) {
      MongoContentStorage storage = new MongoContentStorage(db);
      String sha = args[2];
      try {
        ContentSHA file = findContentByPrefix(storage, sha);
        if (file == null)
          throw new FileNotFoundException("-sha " + sha);
        String[] path = getPath(args[3], args[4]);
        createFile(fs, file, path, null);
      } catch (DecoderException e) {
        throw new IllegalArgumentException("invalid parameter :" + sha
            + " is not a hex-encoded SHA-1 prefix");
      }
    } else {
      String[] srcPath = getPath(args[1], args[2]);
      String[] targetPath = getPath(args[3], args[4]);
      V7File src = fs.getFile(srcPath);
      if (src == null) {
        throw new FileNotFoundException(args[1] + " " + args[2]);
      }
      if (src.hasContent()) {
        createFile(fs, src.getContentPointer(), targetPath, src
            .getContentType());
      } else {
        V7File existing = fs.getFile(targetPath);
        if (existing != null) {
          throw new IOException("copy target " + targetPath
              + " already exists");
        }
        V7File parent = getParent(fs, targetPath);
View Full Code Here

      endpointProperties = new Properties(Configuration
          .getEndpointProperties(endpoint));
      // need to adjust mongo.db in case of multi-tenant mode
      endpointProperties.put("mongo.db", dbName);

      fs = new V7GridFS(mongo.getDB(dbName));

      ROOT = getProperty("root");
      if (ROOT == null)
        ROOT = endpoint;
View Full Code Here

TOP

Related Classes of v7db.files.mongodb.V7GridFS

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.