Package v7db.files.mongodb

Examples of v7db.files.mongodb.MongoContentStorage


public class ContentConcatenationTest extends MockMongoTestCaseSupport {

  public void testContentRepetition() throws IOException {

    ContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));
    {
      Content doubled = new ContentConcatenation().getContent(storage,
          new BasicBSONObject("store", "cat").append("base",
              new InlineContent("abcde".getBytes(), 0, 10)
                  .serialize()));

      assertEquals("abcdeabcde", IOUtils.toString(doubled
          .getInputStream()));
      assertEquals(10l, doubled.getLength());
    }
    {
      ContentSHA one = storage.storeContent(new ByteArrayInputStream(
          "abcde".getBytes()));

      Content doubled = new ContentConcatenation().getContent(storage,
          new BasicBSONObject("store", "cat").append("base",
              new BasicBSONObject("store", "cat").append("base",
                  new StoredContent(one.getSHA(), 10)
                      .serialize())));

      assertEquals("abcdeabcde", IOUtils.toString(doubled
          .getInputStream()));
      assertEquals(10l, doubled.getLength());
    }
    {
      ContentSHA one = storage.storeContent(new ByteArrayInputStream(
          "abcde".getBytes()));

      Content doubled = new ContentConcatenation().getContent(storage,
          new BasicBSONObject("store", "cat").append("base",
              new BasicBSONObject("store", "cat").append("base",
View Full Code Here


public class ZipFileTest extends MockMongoTestCaseSupport {

  public void testPullOutFileFromZip() throws MongoException, IOException,
      ZipException, DecoderException {

    ContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));

    ContentPointer zip = storage.storeContent(getClass()
        .getResourceAsStream("mongodb.epub"));

    ContentPointer png = ZipFile.extractFile(storage, zip,
        "images/img0.png");

    assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils
        .shaHex(storage.getContent(png).getInputStream()));

  }
View Full Code Here

  }

  public void testIndexZipFile() throws MongoException, IOException,
      ZipException, DecoderException {

    ContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));

    ContentPointer zip = storage.storeContent(getClass()
        .getResourceAsStream("mongodb.epub"));

    ZipFile.index(storage, zip);

    assertEquals("fc012bb0439382f709d3caebab958ff592811d17", DigestUtils
        .shaHex(storage.getContent(
            decodeHex("fc012bb0439382f709d3caebab958ff592811d17"
                .toCharArray())).getInputStream()));

  }
View Full Code Here

        .getDefaultProperties());

  }

  public void testSHA() throws IOException {
    MongoContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));
    ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test"
        .getBytes()));

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

            "Bucket '1' does not have a file matching digest '1234'",
            e.getResponseMessage());
      }
    }

    MongoContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));
    ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test"
        .getBytes()));
    {
      WebRequest request = new GetMethodWebRequest(
          "http://test/myServlet/1");
      request.setParameter("sha", sha.getDigest());
View Full Code Here

  }

  public void testFormPostGET() throws IOException, SAXException {

    BasicBSONObject bucket = prepareBucket("1", "FormPost", null, null);
    MongoContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));
    ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test"
        .getBytes()));
    ServletUnitClient sc = sr.newClient();
    {
      WebRequest request = new GetMethodWebRequest(
          "http://test/myServlet/1");
View Full Code Here

    realOut = System.out;
    System.setOut(new PrintStream(out));
  }

  public void testSha() throws IOException {
    MongoContentStorage storage = new MongoContentStorage(getMongo().getDB(
        "test"));
    ContentSHA sha = storage.storeContent(new ByteArrayInputStream("test"
        .getBytes()));
    CatCommand.main(new String[] { "cat", "-sha", sha.getDigest() });
    System.out.flush();
    assertEquals("test", out.toString());
  }
View Full Code Here

          .println("Upload the contents of one or more files and print their SHA digests:");
      System.err.println("   upload <file> [file] [file] [...]");
      System.exit(1);
    }

    ContentStorage storage = new MongoContentStorage(Configuration
        .getMongo().getDB(Configuration.getProperty("mongo.db")));

    for (int i = 1; i < args.length; i++) {
      File f = new File(args[i]);
      if (f.isFile() && f.canRead()) {
        try {
          ContentSHA up = storage
              .storeContent(new FileInputStream(f));

          // TODO: display if chunked or not
          System.out.format("-      %10d %80s %40s\n", f.length(), f
              .getName(), up.getDigest());
View Full Code Here

      System.err.println("  by hash:   cat -sha <shaHex>");
      System.exit(1);
    }

    if ("-sha".equals(args[1])) {
      MongoContentStorage storage = new MongoContentStorage(Configuration
          .getMongo().getDB(Configuration.getProperty("mongo.db")));
      String sha = args[2];
      try {
        Content file = findContentByPrefix(storage, sha);
        if (file == null) {
View Full Code Here

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

TOP

Related Classes of v7db.files.mongodb.MongoContentStorage

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.