Search in sources :

Example 1 with WriteCallback

use of org.apache.wicket.request.resource.AbstractResource.WriteCallback in project wicket by apache.

the class WriteCallbackTest method writeStream.

/**
 */
@Test
public void writeStream() throws IOException {
    WriteCallback callback = new WriteCallback() {

        @Override
        public void writeData(Attributes attributes) {
        }
    };
    ByteArrayResponse response = new ByteArrayResponse();
    Attributes attributes = new Attributes(new MockWebRequest(new Url()), response);
    byte[] srcData = new byte[5000];
    for (int i = 0; i < srcData.length; i++) {
        srcData[i] = (byte) i;
    }
    InputStream in = new ByteArrayInputStream(srcData);
    callback.writeStream(attributes, in);
    assertTrue("Content not equal", Arrays.equals(response.getBytes(), srcData));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attributes(org.apache.wicket.request.resource.IResource.Attributes) WriteCallback(org.apache.wicket.request.resource.AbstractResource.WriteCallback) MockWebRequest(org.apache.wicket.mock.MockWebRequest) ByteArrayResponse(org.apache.wicket.response.ByteArrayResponse) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 MockWebRequest (org.apache.wicket.mock.MockWebRequest)1 Url (org.apache.wicket.request.Url)1 WriteCallback (org.apache.wicket.request.resource.AbstractResource.WriteCallback)1 Attributes (org.apache.wicket.request.resource.IResource.Attributes)1 ByteArrayResponse (org.apache.wicket.response.ByteArrayResponse)1 Test (org.junit.Test)1