Package v7db.files.spi

Examples of v7db.files.spi.Content


    byte[] data = "abcdefghijklmnopqrstuvwxyz".getBytes();

    ContentPointer pointer = storage.storeContent(new ByteArrayInputStream(
        data));
    Content check = storage.getContent(pointer);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();

  }
View Full Code Here


    Mongo mongo = getMongo();
    ContentStorage storage = new MongoContentStorage(mongo.getDB("test")
        .getCollection("v7files.content"));

    Content check = storage.getContent(sha);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();

  }
View Full Code Here

    Mongo mongo = getMongo();
    ContentStorage storage = new MongoContentStorage(mongo.getDB("test")
        .getCollection("v7files.content"));

    Content check = storage.getContent(sha);

    assertEquals(new String(data), IOUtils.toString(check.getInputStream()));
    assertEquals(data.length, check.getLength());
    mongo.close();

  }
View Full Code Here

    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) {
          System.err.println("file not found");
          System.exit(1);
        }
        IOUtils.copy(file.getInputStream(), System.out);
      } catch (DecoderException e) {
        System.err.println("invalid parameter :" + sha
            + " 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

      throws IOException {
    if (shaPrefix.length == 20) {
      DBObject file = contentCollection.findOne(shaPrefix);
      if (file == null)
        return null;
      Content c = getContent(file);
      return ContentSHA.forDigestAndLength(shaPrefix, c.getLength());
    }

    if (shaPrefix.length > 20)
      throw new IllegalArgumentException();

    byte[] lower = Arrays.copyOf(shaPrefix, 20); // 0-padded
    byte[] higher = Arrays.copyOf(shaPrefix, 20); // FF-padded
    for (int i = shaPrefix.length; i < higher.length; i++) {
      higher[i] = (byte) 0xFF;
    }
    List<DBObject> files = contentCollection.find(
        QueryUtils.between(_ID, lower, higher), new BasicDBObject())
        .limit(2).toArray();
    if (files.isEmpty())
      return null;
    if (files.size() == 1) {
      Content c = getContent(files.get(0));
      return ContentSHA.forDigestAndLength(
          (byte[]) files.get(0).get(_ID), c.getLength());
    }
    throw new IllegalArgumentException(Hex.encodeHexString(shaPrefix)
        + " is not a unique SHA prefix");
  }
View Full Code Here

    if (pointer instanceof ContentSHA) {
      ContentSHA p = (ContentSHA) pointer;
      byte[] sha = p.getSHA();

      Content base = getContent(sha);
      if (base == null)
        throw new IllegalArgumentException("base SHA not found: "
            + Hex.encodeHexString(sha));

      return base;

    }

    if (pointer instanceof StoredContent) {
      StoredContent p = (StoredContent) pointer;
      byte[] sha = p.getBaseSHA();

      Content base = getContent(sha);
      if (base == null)
        throw new IllegalArgumentException("base SHA not found: "
            + Hex.encodeHexString(sha));

      if (p.getLength() != base.getLength()) {
        return new OffsetAndLength(base, 0, p.getLength());
      }

      return base;
View Full Code Here

          + "' does not have a file matching digest '"
          + Hex.encodeHexString(sha) + "'");
      return;
    }

    Content content = storage.getContent(sha);
    if (content == null) {
      response
          .sendError(
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "Bucket '"
View Full Code Here

  private void doEchoPutGet(HttpServletRequest request,
      HttpServletResponse response, BSONObject bucket, byte[] sha)
      throws IOException {

    Content content = storage.getContent(sha);

    if (content == null) {
      response.sendError(HttpServletResponse.SC_NOT_FOUND, "Bucket '"
          + bucket.get("_id")
          + "' does not have a file matching digest '"
View Full Code Here

   *
   * @throws IOException
   */
  public static final void index(ContentStorage storage,
      ContentPointer zipFile) throws IOException {
    Content zip = storage.getContent(zipFile);
    if (zip == null)
      throw new IllegalArgumentException("invalid ContentPointer "
          + zipFile);

    File tmp = File.createTempFile("v7files_zipfile_extractfile_", ".zip");
    try {
      OutputStream f = new FileOutputStream(tmp);
      IOUtils.copy(zip.getInputStream(), f);
      f.close();

      // open up the zip file
      HeaderReader r = new HeaderReader(new RandomAccessFile(tmp, "r"));
      ZipModel model = r.readAllHeaders();
View Full Code Here

   *             if the ContentPointer does not refer to a zip archive
   *
   */
  public static final ContentPointer extractFile(ContentStorage storage,
      ContentPointer zipFile, String fileName) throws IOException {
    Content zip = storage.getContent(zipFile);
    if (zip == null)
      throw new IllegalArgumentException("invalid ContentPointer "
          + zipFile);

    File tmp = File.createTempFile("v7files_zipfile_extractfile_", ".zip");
    try {
      OutputStream f = new FileOutputStream(tmp);
      IOUtils.copy(zip.getInputStream(), f);
      f.close();

      // open up the zip file
      HeaderReader r = new HeaderReader(new RandomAccessFile(tmp, "r"));
      ZipModel model = r.readAllHeaders();
View Full Code Here

TOP

Related Classes of v7db.files.spi.Content

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.