FileMetadata

com.google.appengine.api.files.dev

Class FileMetadata

  • java.lang.Object
    • com.google.appengine.api.files.dev.FileMetadata
  • Direct Known Subclasses:
    BlobstoreFile, GSFile


    public abstract class FileMetadata
    extends java.lang.Object
    This class represents a single file stored by the local file service. This class is abstract. There are concrete subclasses corresponding to each of the concrete backend storage repositories.
    • Field Detail

      • contentType

        protected ContentType contentType
      • finalized

        protected boolean finalized
      • readName

        protected final java.lang.String readName
        The name of the readable version of this file once it is finalized.
      • appendName

        protected final java.lang.String appendName
        The name of the appendable version of this unfinalized file.
      • currentSequenceKey

        protected java.lang.String currentSequenceKey
        If this instance is for writing and it has not yet been finalized, then this variable stores the current sequence key
      • tempBytes

        protected java.io.ByteArrayOutputStream tempBytes
        If this instance is for writing and it has not yet been finalized, then this variable stores the current bytes. These bytes will be copied to the remote file during finalization.
      • tempBytesSizeWhenFinalized

        protected int tempBytesSizeWhenFinalized
    • Constructor Detail

      • FileMetadata

        public FileMetadata(java.lang.String readName,
                            java.lang.String appendName,
                            ContentType contentType)
    • Method Detail

      • getTempBytesSize

        protected final int getTempBytesSize()
      • getAppendName

        public java.lang.String getAppendName()
      • setFinalized

        public void setFinalized()
      • getBlobInfo

        public abstract com.google.appengine.api.blobstore.BlobInfo getBlobInfo()
        Returns:
        the BlobInfo of the file. File must have been finalized.
        Throws:
        {@link - IllegalStateException} if file is not finalized.
        {@link - com.google.apphosting.api.ApiProxy.ApplicationException} if the blobInfo can't be found for any other reasons.
      • isFinalized

        public boolean isFinalized()
      • getContentType

        public ContentType getContentType()
      • lock

        public void lock(Session session)
      • isOpenInDifferentSession

        public boolean isOpenInDifferentSession(Session session)
      • read

        public ByteString read(ReadRequest request)
        Handle a Read request
        Parameters:
        request - the request
        Returns:
        A ByteString containing the read bytes
      • append

        public void append(AppendRequest request)
        Handle an append request
        Parameters:
        request - the request
      • getInputStream

        protected abstract java.io.InputStream getInputStream()
                                                       throws java.io.IOException
        Throws:
        java.io.IOException
      • getOutputStream

        protected abstract java.io.OutputStream getOutputStream()
                                                         throws java.io.IOException
        Throws:
        java.io.IOException
      • checkParameters

        protected static void checkParameters(java.util.Map<java.lang.String,java.lang.String> parameters,
                                              java.lang.String... names)
      • copy

        protected static long copy(java.io.InputStream from,
                                   java.io.OutputStream to,
                                   long maxBytes)
                            throws java.io.IOException
        Copies maxBytes bytes from the input stream to the output stream.
        Throws:
        java.io.IOException
      • saveBlobInfo

        protected void saveBlobInfo(com.google.appengine.api.datastore.DatastoreService datastore,
                                    com.google.appengine.api.blobstore.BlobKey blobKey,
                                    java.lang.String entityKind,
                                    java.lang.String mimeType,
                                    long currentTime,
                                    java.lang.String fileName,
                                    java.lang.String creationHandle)
      • newReadableInstance

        public static FileMetadata newReadableInstance(LocalFileService localFileService,
                                                       Clock clock,
                                                       ParsedFileName parsedName)
        Returns a new instance of FileMetadata if possible. This method is called in response to an Open-for-Read request in the case that no meta-data is found for the requested file in the in-memory cache. If it is determined that the given file name corresponds to an existing, finalized file, then an instance of FileMetadata will be returned. Otherwise null will be returned.
        Returns:
        An instance of FileMetadata or null if no corresponding entity could be found in the datastore.