edu.ucsb.nceas.metacat.restservice.multipart

## 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 Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static java.lang.String` | `SYSMETA`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `StreamingMultipartRequestResolver(java.lang.String tmpUploadDir, int maxUploadSize)` Constructor

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static void` | `deleteTempFile(java.io.File temp)` Delete a temp file either immediately or on program exists according to the configuration
    `org.dataone.service.types.v1.SystemMetadata` | `getSystemMetadataPart()` Get the system metadata object which was extracted from the sysmeta part.
    `org.dataone.mimemultipart.MultipartRequest` | `resolveMultipart(javax.servlet.http.HttpServletRequest request)`
    `static CheckedFile` | `writeStreamToCheckedFile(java.io.File file, java.io.InputStream dataStream, java.lang.String checksumAlgorithm, java.lang.String pid)` Write the input stream into the given fileName and directory while calculate the checksum.

    - ### Methods inherited from class org.dataone.mimemultipart.MultipartRequestResolver

      `isMultipartContent`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### SYSMETA

          public static final java.lang.String SYSMETA

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### StreamingMultipartRequestResolver

          public StreamingMultipartRequestResolver(java.lang.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 Detail

    - #### resolveMultipart

          public org.dataone.mimemultipart.MultipartRequest resolveMultipart(javax.servlet.http.HttpServletRequest request)
                                                                      throws java.io.IOException,
                                                                             org.apache.commons.fileupload.FileUploadException,
                                                                             java.lang.InstantiationException,
                                                                             java.lang.IllegalAccessException,
                                                                             org.dataone.exceptions.MarshallingException,
                                                                             java.security.NoSuchAlgorithmException

      Overrides:
        `resolveMultipart` in class `org.dataone.mimemultipart.MultipartRequestResolver`
      Throws:
        `java.io.IOException`
        `org.apache.commons.fileupload.FileUploadException`
        `java.lang.InstantiationException`
        `java.lang.IllegalAccessException`
        `org.dataone.exceptions.MarshallingException`
        `java.security.NoSuchAlgorithmException`

    - #### writeStreamToCheckedFile

          public static CheckedFile writeStreamToCheckedFile(java.io.File file,
                                                             java.io.InputStream dataStream,
                                                             java.lang.String checksumAlgorithm,
                                                             java.lang.String pid)
                                                      throws java.security.NoSuchAlgorithmException,
                                                             java.io.FileNotFoundException,
                                                             java.io.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:
        `java.security.NoSuchAlgorithmException`
        `java.io.FileNotFoundException`
        `java.io.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(java.io.File temp)

      Delete a temp file either immediately or on program exists according to the configuration
      Parameters:
        `temp` - the file will be deleted

Copyright © 2023 Regents of the University of California. All Rights Reserved.