Skip to content

Commit

Permalink
added addStream methods
Browse files Browse the repository at this point in the history
  • Loading branch information
fracpete committed Sep 13, 2019
1 parent dd73b29 commit bb06ee2
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions src/main/java/com/github/fracpete/requests4j/form/FormData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

package com.github.fracpete.requests4j.form;

import org.apache.tika.mime.MediaType;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -50,7 +53,7 @@ public FormData add(AbstractParameter param) {
/**
* Adds the string form parameter.
*
* @param name the name
* @param name the parameter name
* @param value the value
* @return itself
*/
Expand All @@ -59,9 +62,9 @@ public FormData add(String name, String value) {
}

/**
* Adds the file form parameter.
* Adds the file as form parameter.
*
* @param name the name
* @param name the parameter name
* @param filename the file to add
* @return itself
*/
Expand All @@ -70,16 +73,42 @@ public FormData addFile(String name, String filename) throws IOException {
}

/**
* Adds the file form parameter.
* Adds the file as form parameter.
*
* @param name the name
* @param name the parameter name
* @param file the file to add
* @return itself
*/
public FormData addFile(String name, File file) throws IOException {
return add(new StreamParameter(name, file));
}

/**
* Adds the stream as form parameter.
*
* @param name the parameter name
* @param file the file name to use for the stream
* @param mimetype the mimetype to use, eg {@link MediaType#OCTET_STREAM}
* @param stream the stream to read from
* @return itself
*/
public FormData addStream(String name, File file, MediaType mimetype, InputStream stream) throws IOException {
return add(new StreamParameter(name, file, mimetype, stream));
}

/**
* Adds the stream as form parameter.
*
* @param name the parameter name
* @param filename the file name to use for the stream
* @param mimetype the mimetype to use, eg {@link MediaType#OCTET_STREAM}
* @param stream the stream to read from
* @return itself
*/
public FormData addStream(String name, String filename, MediaType mimetype, InputStream stream) throws IOException {
return add(new StreamParameter(name, filename, mimetype, stream));
}

/**
* Writes out the parameters.
*
Expand Down

0 comments on commit bb06ee2

Please sign in to comment.