Class MemoryObjectStorage

java.lang.Object
com.codename1.backend.storage.MemoryObjectStorage
All Implemented Interfaces:
ObjectStorage

public final class MemoryObjectStorage extends Object implements ObjectStorage

An ObjectStorage held in this process, for tests and local development. Nothing survives a restart.

It cannot presign: a URL has to name a server that answers it, and this store has none. Both presign methods throw, so code that hands one to a client fails in development rather than shipping a URL that leads nowhere.

  • Constructor Details

    • MemoryObjectStorage

      public MemoryObjectStorage()
  • Method Details

    • getName

      public String getName()
      Description copied from interface: ObjectStorage
      The provider's short name: s3 (Amazon S3 and every S3-compatible endpoint, R2 included), gcs, azure or memory.
      Specified by:
      getName in interface ObjectStorage
    • createBucket

      public void createBucket(String bucket)
      Description copied from interface: ObjectStorage

      Creates a bucket, and says nothing when this account already owns it.

      Usually infrastructure's job, but a first run against an emulator or a test fixture needs it.

      Specified by:
      createBucket in interface ObjectStorage
    • putObject

      public String putObject(String bucket, String key, byte[] content, String contentType) throws IOException
      Description copied from interface: ObjectStorage

      Uploads an object, replacing one of the same key. Returns its ETag, the provider's receipt for exactly these bytes.

      contentType may be null, which stores application/octet-stream.

      Specified by:
      putObject in interface ObjectStorage
      Throws:
      IOException
    • getObject

      public byte[] getObject(String bucket, String key) throws IOException
      Description copied from interface: ObjectStorage
      Downloads an object. Throws when it is missing, rather than returning null.
      Specified by:
      getObject in interface ObjectStorage
      Throws:
      IOException
    • headObject

      public ObjectInfo headObject(String bucket, String key) throws IOException
      Description copied from interface: ObjectStorage
      The object's metadata, or null when it does not exist.
      Specified by:
      headObject in interface ObjectStorage
      Throws:
      IOException
    • deleteObject

      public void deleteObject(String bucket, String key) throws IOException
      Description copied from interface: ObjectStorage
      Deletes an object. Deleting one that is not there is not an error.
      Specified by:
      deleteObject in interface ObjectStorage
      Throws:
      IOException
    • listObjects

      public List<String> listObjects(String bucket, String prefix, int max) throws IOException
      Description copied from interface: ObjectStorage
      Up to max keys under prefix (null or empty for all), following the provider's pagination until the listing ends or max is reached. Zero answers an empty list; a negative max is refused.
      Specified by:
      listObjects in interface ObjectStorage
      Throws:
      IOException
    • presignGet

      public String presignGet(String bucket, String key, int seconds) throws IOException
      Description copied from interface: ObjectStorage

      A URL that downloads the object with no credentials, for seconds.

      Computed, not requested, wherever the provider allows it: the URL can be handed straight to a client. A lifetime the provider refuses -- zero or less, or past seven days on S3, R2 and GCS -- throws an IOException on every provider, so moving between them does not change how it fails.

      Specified by:
      presignGet in interface ObjectStorage
      Throws:
      IOException
    • presignPut

      public String presignPut(String bucket, String key, int seconds) throws IOException
      Description copied from interface: ObjectStorage

      The upload counterpart: a URL a client can PUT the bytes to, for seconds.

      Azure needs one header on that PUT that the others do not: x-ms-blob-type: BlockBlob. A client that serves more than one provider can send it everywhere; S3 and GCS ignore it.

      Specified by:
      presignPut in interface ObjectStorage
      Throws:
      IOException