import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
-import java.util.Map;
-import java.util.Map.Entry;
import net.pterodactylus.fcp.FileEntry.DirectFileEntry;
* The file entry to add
*/
public void addFileEntry(FileEntry fileEntry) {
- Map<String, String> fields = fileEntry.getFields();
- for (Entry<String, String> fieldEntry : fields.entrySet()) {
- setField("Files." + fileIndex + "." + fieldEntry.getKey(), fieldEntry.getValue());
- }
+ fileEntry.getFields().forEach((key, value) -> setField("Files." + fileIndex + "." + key, value));
+ directFileInputStreams.add(fileEntry.getInputStream());
fileIndex++;
- if (fileEntry instanceof FileEntry.DirectFileEntry) {
- directFileInputStreams.add(((DirectFileEntry) fileEntry).getInputStream());
- }
}
/**
package net.pterodactylus.fcp;
+import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
*
* @return The fields for this file entry
*/
- abstract Map<String, String> getFields();
+ protected abstract Map<String, String> getFields();
+
+ /**
+ * Returns an {@link InputStream} delivering the content of this file. If
+ * this file entry is not of type {@link UploadFrom#direct}, the input
+ * stream returned by this method is empty.
+ *
+ * @return An {@link InputStream} delivering the content of a
+ * {@link UploadFrom#direct} file entry, or an empty input stream
+ */
+ public InputStream getInputStream() {
+ return new ByteArrayInputStream(new byte[0]);
+ }
/**
* A file entry for a file that should be transmitted in the payload of the
* {@inheritDoc}
*/
@Override
- Map<String, String> getFields() {
+ protected Map<String, String> getFields() {
Map<String, String> fields = new HashMap<String, String>();
fields.put("Name", name);
fields.put("UploadFrom", String.valueOf(uploadFrom));
*
* @return The input stream of the file
*/
- InputStream getInputStream() {
+ @Override
+ public InputStream getInputStream() {
return inputStream;
}
* {@inheritDoc}
*/
@Override
- Map<String, String> getFields() {
+ protected Map<String, String> getFields() {
Map<String, String> fields = new HashMap<String, String>();
fields.put("Name", name);
fields.put("UploadFrom", String.valueOf(uploadFrom));
* {@inheritDoc}
*/
@Override
- Map<String, String> getFields() {
+ protected Map<String, String> getFields() {
Map<String, String> fields = new HashMap<String, String>();
fields.put("Name", name);
fields.put("UploadFrom", String.valueOf(uploadFrom));