Package com.jcabi.s3

Class Bucket.Prefixed

java.lang.Object
com.jcabi.s3.Bucket.Prefixed
All Implemented Interfaces:
Bucket, Comparable<Bucket>
Enclosing interface:
Bucket

@Loggable(1) public static final class Bucket.Prefixed extends Object implements Bucket
Creates bucket with specified origin bucket and prefix.

Basically this class is used to cut off ocket keys of underlying bucket by some string known as prefix. If key is not started with prefix, it will be omitted

Example of usage:

 final Region region = new MkRegion(
   new TemporaryFolder().newFolder()
 );
 final Bucket bucket = region.bucket("test");
 new Ocket.Text(bucket.ocket("a/first.txt")).write("");
 new Ocket.Text(bucket.ocket("a/b/hello.txt")).write("");
 new Ocket.Text(bucket.ocket("a/b/f/2.txt")).write("");
 Bucket.Prefixed prefixed = new Bucket.Prefixed(
   bucket, "a/b/"
 );
 Iterable<String> list = prefixed.list(
   ""
 ); // contains "hello.txt" and "f/2.txt"
 
Since:
0.1
  • Constructor Details

    • Prefixed

      public Prefixed(Bucket bucket, String pfx)
      Public ctor.
      Parameters:
      bucket - Original bucket
      pfx - Prefix
  • Method Details

    • region

      public Region region()
      Description copied from interface: Bucket
      Get region we're in.
      Specified by:
      region in interface Bucket
      Returns:
      Region
    • name

      public String name()
      Description copied from interface: Bucket
      Get bucket name.
      Specified by:
      name in interface Bucket
      Returns:
      Bucket name
    • ocket

      public Ocket ocket(String key)
      Description copied from interface: Bucket
      Get object.
      Specified by:
      ocket in interface Bucket
      Parameters:
      key - Name of it in the bucket
      Returns:
      Ocket
    • exists

      public boolean exists() throws IOException
      Description copied from interface: Bucket
      Checks if the bucket exists.
      Specified by:
      exists in interface Bucket
      Returns:
      If the bucket exists true, otherwise false
      Throws:
      IOException - If any failure happens
    • remove

      public void remove(String key) throws IOException
      Description copied from interface: Bucket
      Delete object from bucket.
      Specified by:
      remove in interface Bucket
      Parameters:
      key - Name of it in the bucket
      Throws:
      IOException - If not found or any other failure
    • list

      public Iterable<String> list(String pfx) throws IOException
      Description copied from interface: Bucket
      List object names with a given prefix.
      Specified by:
      list in interface Bucket
      Parameters:
      pfx - Prefix to use
      Returns:
      Iterable of names
      Throws:
      IOException - If fails
    • compareTo

      public int compareTo(Bucket bucket)
      Specified by:
      compareTo in interface Comparable<Bucket>