Package net.noderunner.amazon.s3.emulator

Examples of net.noderunner.amazon.s3.emulator.Server


    * Returns a map containing all key-value pairs for the given FQN, or null
    * if the node is not present.
    */
   public Map get(Fqn name) throws Exception
   {
      GetStreamResponse response = connection.getStream(getBucket(), key(name));
      try
      {
         if (trace)
         {
            log.trace("get " + name + " response=" + response);
         }

         if (response.isNotFound())
            return null;
         if (!response.isOk())
            throw new S3Exception("get failed " + response);

         BufferedInputStream is = new BufferedInputStream(response.getInputStream());
         Map map = (Map) getMarshaller().objectFromStream(is);
         response.release();
         return map;
      }
      finally
      {
         response.release();
      }
   }
View Full Code Here


    * Returns a map containing all key-value pairs for the given FQN, or null
    * if the node is not present.
    */
   public Map get(Fqn name) throws Exception
   {
      GetStreamResponse response = connection.getStream(getBucket(), key(name));
      try
      {
         if (trace)
         {
            log.trace("get " + name + " response=" + response);
         }

         if (response.isNotFound())
            return null;
         if (!response.isOk())
            throw new S3Exception("get failed " + response);

         BufferedInputStream is = new BufferedInputStream(response.getInputStream());
         Map map = (Map) getMarshaller().objectFromStream(is);
         response.release();
         return map;
      }
      finally
      {
         response.release();
      }
   }
View Full Code Here

          log("map.get(" + key + ") = " + obj);
      if (obj == null) {
        resp.sendError(404, "Not here: " + e);
        return;
      }
      Headers h = new Headers();
      h = h.mergeMetadata(obj.getMetadata());
      for (Map.Entry<String, List<String>> me : h.getHeaders().entrySet()) {
        for (String v : me.getValue()) {
          resp.setHeader(me.getKey(), v);
        }
      }
      resp.getOutputStream().write(obj.getData());
View Full Code Here

          break;
        os.write(b, 0, len);
      }
      S3Object s3 = new S3Object(os.toByteArray());
      map.put(e, s3);
      Headers h = new Headers();
      @SuppressWarnings("unchecked")
      Enumeration<String> names = req.getHeaderNames();
      for (String n : Collections.list(names))
        h.put(n, req.getHeader(n));
      s3.setMetadata(h.extractMetadata());
      log("put '" + e + "' as: " + s3);
    }
  }
View Full Code Here

  /**
   * Writes an ISO801 date.
   */
  public Writer write(Date lastModified) {
    return write(new ISO801DateFormat().format(lastModified));
  }
View Full Code Here

    * returns null if the parent node is not found or if no children are found.
    */
   public Set<String> getChildrenNames(Fqn name) throws Exception
   {
      String children = children(name);
      ListResponse response = connection.list(getBucket(), children);
      if (trace)
      {
         log.trace("getChildrenNames " + name + " response=" + response);
      }
      if (response.isNotFound())
         return null;
      if (!response.isOk())
         throw new Exception("List failed " + response);

      Set<String> set = new HashSet<String>();
      for (Entry e : response.getEntries())
      {
         // TODO decode prefix
         set.add(e.getKey().substring(children.length() + 1));
      }

View Full Code Here

    * returns null if the parent node is not found or if no children are found.
    */
   public Set<String> getChildrenNames(Fqn name) throws Exception
   {
      String children = children(name);
      ListResponse response = connection.list(getBucket(), children);
      if (trace)
      {
         log.trace("getChildrenNames " + name + " response=" + response);
      }
      if (response.isNotFound())
         return null;
      if (!response.isOk())
         throw new Exception("List failed " + response);

      Set<String> set = new HashSet<String>();
      for (Entry e : response.getEntries())
      {
         // TODO decode prefix
         set.add(e.getKey().substring(children.length() + 1));
      }

View Full Code Here

    * returns null if the parent node is not found or if no children are found.
    */
   public Set<String> getChildrenNames(Fqn name) throws Exception
   {
      String children = children(name);
      ListResponse response = connection.list(getBucket(), children);
      if (trace)
      {
         log.trace("getChildrenNames " + name + " response=" + response);
      }
      if (response.isNotFound())
         return null;
      if (!response.isOk())
         throw new Exception("List failed " + response);

      Set<String> set = new HashSet<String>();
      for (Entry e : response.getEntries())
      {
         // TODO decode prefix
         set.add(e.getKey().substring(children.length() + 1));
      }

View Full Code Here

      bucket = true;
    } else {
      Entry e = new Entry(key(uri));
      e.setLastModified(new Date());
      e.setSize(req.getContentLength());
      e.setOwner(new Owner("id", "name"));
      ByteArrayOutputStream os = new ByteArrayOutputStream();
      ServletInputStream is = req.getInputStream();
      byte b[] = new byte[128];
      while (true) {
        int len = is.read(b);
View Full Code Here

   {
      log.debug("Starting");
      try
      {
         this.connection = config.getConnection();
         Response create = connection.create(getBucket(), config.getLocation());
         if (!create.isOk())
            throw new S3Exception("Unable to create bucket: " + create);
         log.info("S3 accessed successfully. Bucket created: " + create);
      }
      catch (Exception e)
      {
View Full Code Here

TOP

Related Classes of net.noderunner.amazon.s3.emulator.Server

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.