List of usage examples for org.apache.http.entity BasicHttpEntity setContent
public void setContent(InputStream inputStream)
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testIsRepeatable() throws Exception { String text = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(text.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic); assertThat(replay.isRepeatable(), is(true)); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(text.getBytes(UTF8))); BufferedHttpEntity buffered = new BufferedHttpEntity(basic); replay = new PartiallyRepeatableHttpEntity(buffered); assertThat(replay.isRepeatable(), is(true)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testIsChunked() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isChunked(), is(false)); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setChunked(true);/*ww w . j ava 2 s . c om*/ replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isChunked(), is(true)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testGetContentLength() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentLength(), is(-1L)); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentLength(input.length()); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentLength(), is(10L)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testGetContentType() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentType(), nullValue()); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentType(ContentType.APPLICATION_JSON.getMimeType()); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentType().getValue(), is("application/json")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testGetContentEncoding() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentEncoding(), nullValue()); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentEncoding("UTF-8"); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentEncoding().getValue(), is("UTF-8")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testConsumeContent() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); try {/*from w w w. ja va 2s . co m*/ replay.consumeContent(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // Expected. } }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_FC_IB__C2_FC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes("UTF-8"))); replay = new PartiallyRepeatableHttpEntity(basic, 20); String output;//from w ww . j av a2s .c o m output = byteRead(replay.getContent(), -1); assertThat(output, is(data)); output = byteRead(replay.getContent(), -1); assertThat(output, is(data)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_FC_IB__C2_FC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes("UTF-8"))); replay = new PartiallyRepeatableHttpEntity(basic, 20); String output;//ww w . j a v a 2 s. com output = blockRead(replay.getContent(), UTF8, -1, 3); assertThat(output, is(data)); output = blockRead(replay.getContent(), UTF8, -1, 3); assertThat(output, is(data)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_FC_OB__C2_AC__EE() throws Exception { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); String output;/*from www .j ava 2 s.co m*/ output = byteRead(replay.getContent(), -1); assertThat(output, is(data)); try { replay.getContent(); fail("Expected IOException"); } catch (IOException e) { // Expected. } }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_FC_OB__C2_AC__EE() throws Exception { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); String output;/*from w w w . j a va2 s . c om*/ output = blockRead(replay.getContent(), UTF8, -1, 3); assertThat(output, is(data)); try { replay.getContent(); fail("Expected IOException"); } catch (IOException e) { // Expected. } }