Commit b15880ca authored by Craig Jones's avatar Craig Jones Committed by Andrea Aime
Browse files

GEOS-7312 - close inputstream after finishing with it when encoding using RawDataPPIO

parent f43a26d5
......@@ -52,7 +52,10 @@ public class RawDataPPIO extends ComplexPPIO {
@Override
public void encode(Object value, OutputStream os) throws Exception {
RawData rd = (RawData) value;
IOUtils.copy(rd.getInputStream(), os);
try (InputStream is = rd.getInputStream()) {
IOUtils.copy(is, os);
};
}
@Override
......
/* (c) 2014 - 2015 Open Source Geospatial Foundation - all rights reserved
* (c) 2014 OpenPlans
* This code is licensed under the GPL 2.0 license, available at the root
* application directory.
*/
package org.geoserver.wps.ppio;
import static org.easymock.EasyMock.expect;
import static org.easymock.classextension.EasyMock.createMock;
import static org.easymock.classextension.EasyMock.replay;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.geoserver.wps.process.RawData;
import org.geoserver.wps.resource.WPSResourceManager;
import org.junit.Test;
public class RawDataPPIOTest {
@Test
public void testInputStreamClosed() throws Exception {
try (
TestInputStream is = new TestInputStream();
OutputStream os = new ByteArrayOutputStream();
) {
RawDataPPIO ppio = buildRawDataPPIOWithMockManager();
RawData rawData = mockRawDataWithInputStream(is);
ppio.encode(rawData, os);
assertTrue(is.isClosed());
}
}
private RawDataPPIO buildRawDataPPIOWithMockManager() {
WPSResourceManager resourceManager = createMock(WPSResourceManager.class);
replay(resourceManager);
return new RawDataPPIO(resourceManager);
}
private RawData mockRawDataWithInputStream(TestInputStream is) throws IOException {
RawData rawData = createMock(RawData.class);
expect(rawData.getInputStream()).andReturn(is);
replay(rawData);
return rawData;
}
private class TestInputStream extends ByteArrayInputStream {
private boolean isClosed = false;
public TestInputStream() {
super("Test data".getBytes());
}
public boolean isClosed() {
return isClosed;
}
@Override
public void close() throws IOException {
super.close();
isClosed = true;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment