Class FileMetadata

  • java.lang.Object
  • 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 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 getBlobInfo()
        the BlobInfo of the file. File must have been finalized.
        {@link - IllegalStateException} if file is not finalized.
        {@link -} 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
        request - the request
        A ByteString containing the read bytes
      • append

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

        protected abstract getInputStream()
      • getOutputStream

        protected abstract getOutputStream()
      • checkParameters

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

        protected static long copy( from,
                                   long maxBytes)
        Copies maxBytes bytes from the input stream to the output stream.
      • saveBlobInfo

        protected void saveBlobInfo( datastore,
                                    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.
        An instance of FileMetadata or null if no corresponding entity could be found in the datastore.