ABAP DUMP ERROR 24시

InputStream 의미 본문

[WEB]Back-end/Java

InputStream 의미

이운형 2022. 3. 6. 15:04
반응형

정리

 


inputStream으로 데이터를 불러오고 StreamUtils로 해석해서 사용한다.

 

1. InputStream이 뭐야?

데이터를 읽어주는 메서드

= 데이터를 Byte 단위로 읽어주는 메소드

내장된 기능을 통해 읽고, 데이터의 컨텐트 타입을 가져오는 기능들을 제공

 

우리는 StreamUtils를 통해

StreamUtils.copyToString(inputStream, StandardCharsets.UTF_8);

 btye로 읽어드린 코드들을 UTF-8 인코더를 사용해서 우리가 이해할수 있는 String으로 만들어준다.

    /**
     * Obtain an <code>InputStream</code> that can be used to retrieve the
     * contents of the file.
     *
     * @return An InputStream for the contents of the file
     *
     * @throws IOException if an I/O occurs while obtaining the stream
     */
    public InputStream getInputStream() throws IOException;

    /**
     * Obtain the content type passed by the browser.
     *
     * @return The content type passed by the browser or <code>null</code> if
     *         not defined.
     */
    public String getContentType();

    /**
     * Obtain the name of the field in the multipart form corresponding to this
     * part.
     *
     * @return The name of the field in the multipart form corresponding to this
     *         part.
     */
    public String getName();

    /**
     * If this part represents an uploaded file, gets the file name submitted
     * in the upload. Returns {@code null} if no file name is available or if
     * this part is not a file upload.
     *
     * @return the submitted file name or {@code null}.
     *
     * @since Servlet 3.1
     */
    public String getSubmittedFileName();

    /**
     * Obtain the size of this part.
     *
     * @return The size of the part if bytes
     */
    public long getSize();

    /**
     * A convenience method to write an uploaded part to disk. The client code
     * is not concerned with whether or not the part is stored in memory, or on
     * disk in a temporary location. They just want to write the uploaded part
     * to a file.
     *
     *  This method is not guaranteed to succeed if called more than once for
     *  the same part. This allows a particular implementation to use, for
     *  example, file renaming, where possible, rather than copying all of the
     *  underlying data, thus gaining a significant performance benefit.
     *
     * @param fileName  The location into which the uploaded part should be
     *                  stored. Relative locations are relative to {@link
     *                  javax.servlet.MultipartConfigElement#getLocation()}
     *
     * @throws IOException if an I/O occurs while attempting to write the part
     */
    public void write(String fileName) throws IOException;

    /**
     * Deletes the underlying storage for a part, including deleting any
     * associated temporary disk file. Although the container will delete this
     * storage automatically this method can be used to ensure that this is done
     * at an earlier time, thus preserving system resources.
     * <p>
     * Containers are only required to delete the associated storage when the
     * Part instance is garbage collected. Apache Tomcat will delete the
     * associated storage when the associated request has finished processing.
     * Behaviour of other containers may be different.
     *
     * @throws IOException if an I/O occurs while attempting to delete the part
     */
    public void delete() throws IOException;

    /**
     * Obtains the value of the specified part header as a String. If there are
     * multiple headers with the same name, this method returns the first header
     * in the part. The header name is case insensitive.
     *
     * @param name  Header name
     * @return      The header value or <code>null</code> if the header is not
     *              present
     */
    public String getHeader(String name);

    /**
     * Obtain all the values of the specified part header.
     * @param name The name of the header of interest. The header name is case
     *             insensitive.
     * @return All the values of the specified part header. If the part did not
     *         include any headers of the specified name, this method returns an
     *         empty Collection.
     */
    public Collection<String> getHeaders(String name);

    /**
     * Get the header names provided for this part.
     * @return a Collection of all the header names provided for this part.
     */
    public Collection<String> getHeaderNames();
}
반응형
Comments