Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99a3bc8
commit c96bfdb
Showing
4 changed files
with
89 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/rest-ng/src/main/java/org/geoserver/rest/converters/InputStreamConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.geoserver.rest.converters; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.springframework.http.HttpInputMessage; | ||
import org.springframework.http.HttpOutputMessage; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.converter.HttpMessageNotReadableException; | ||
import org.springframework.http.converter.HttpMessageNotWritableException; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by tbarsballe on 2017-03-31. | ||
*/ | ||
public class InputStreamConverter extends BaseMessageConverter { | ||
@Override | ||
public boolean canRead(Class clazz, MediaType mediaType) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canWrite(Class clazz, MediaType mediaType) { | ||
return InputStream.class.isAssignableFrom(clazz); | ||
} | ||
|
||
@Override | ||
public List<MediaType> getSupportedMediaTypes() { | ||
return Arrays.asList(MediaType.ALL); | ||
} | ||
|
||
@Override | ||
public Object read(Class clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public void write(Object o, MediaType contentType, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { | ||
IOUtils.copy((InputStream)o,outputMessage.getBody()); | ||
((InputStream) o).close(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters