Class StreamingMultipartRequestResolver

java.lang.Object
org.dataone.mimemultipart.MultipartRequestResolver
edu.ucsb.nceas.metacat.restservice.multipart.StreamingMultipartRequestResolver

public class StreamingMultipartRequestResolver extends org.dataone.mimemultipart.MultipartRequestResolver
This class will stream the file parts of the multipart request into a temporary file. During the streaming, the checksum of the tmp file will be calculated and maintained. The temple file with the checksum can be moved to the permanent location rather than copying (read/write). So we only need to read/write once and the performance can be improved.
Author:
tao
  • Field Details

  • Constructor Details

    • StreamingMultipartRequestResolver

      public StreamingMultipartRequestResolver(String tmpUploadDir, int maxUploadSize)
      Constructor
      Parameters:
      tmpUploadDir - the directory will temporarily host the stored files from the file parts in the http multiparts request.
      maxUploadSize - the threshold size of files which can be allowed to upload
  • Method Details

    • resolveMultipart

      public org.dataone.mimemultipart.MultipartRequest resolveMultipart(javax.servlet.http.HttpServletRequest request) throws IOException, org.apache.commons.fileupload.FileUploadException, InstantiationException, IllegalAccessException, org.dataone.exceptions.MarshallingException, NoSuchAlgorithmException
      Overrides:
      resolveMultipart in class org.dataone.mimemultipart.MultipartRequestResolver
      Throws:
      IOException
      org.apache.commons.fileupload.FileUploadException
      InstantiationException
      IllegalAccessException
      org.dataone.exceptions.MarshallingException
      NoSuchAlgorithmException
    • writeStreamToCheckedFile

      public static CheckedFile writeStreamToCheckedFile(File file, InputStream dataStream, String checksumAlgorithm, String pid) throws NoSuchAlgorithmException, FileNotFoundException, IOException
      Write the input stream into the given fileName and directory while calculate the checksum.
      Parameters:
      file - the file into which the stream will be written. It should exists already.
      dataStream - the source stream
      checksumAlgorithm - the algorithm will be used for calculating the checksum
      pid - the pid of the object (only used for debug information)
      Returns:
      a CheckedFile object ( a File object with advertised checksum)
      Throws:
      NoSuchAlgorithmException
      FileNotFoundException
      IOException
    • getSystemMetadataPart

      public org.dataone.service.types.v1.SystemMetadata getSystemMetadataPart()
      Get the system metadata object which was extracted from the sysmeta part. The sysmeta wasn't stored in a file and was created an object directly.
    • deleteTempFile

      public static void deleteTempFile(File temp)
      Delete a temp file either immediately or on program exists according to the configuration
      Parameters:
      temp - the file will be deleted