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 testIsStreaming() throws Exception { String input = "0123456789"; BasicHttpEntity basic; InputStreamEntity streaming;/* www .j a v a2 s . c o m*/ PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(true)); basic = new BasicHttpEntity(); basic.setContent(null); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(false)); streaming = new InputStreamEntity(new ByteArrayInputStream(input.getBytes(UTF8)), 10, ContentType.TEXT_PLAIN); replay = new PartiallyRepeatableHttpEntity(streaming, 5); assertThat(replay.isStreaming(), is(true)); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testS_C1_PC_OB() throws IOException { try {/*from w w w . j a v a 2 s .co m*/ String data = "0123456789"; BasicHttpEntity basic; CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, -1); fail("Expected IOException"); assertThat(text, is("0123456789")); stream.close(); } catch (IOException e) { // expected } }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;/*from w w w .ja v a 2 s . c o m*/ String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, 3); assertThat(text, is("012")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_PC_IB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;//from w w w. ja v a 2 s . c o m String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, 3, 3); assertThat(text, is("012")); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testS_C1_PC_OB__C2_AC__EE() throws IOException { String data = "0123456789"; BasicHttpEntity basic; CappedBufferHttpEntity replay;/* w w w . ja v a2 s. c om*/ InputStream stream; String text; try { basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, 7); assertThat(text, is("0123456")); stream.close(); fail("Expected IOException"); } catch (IOException e) { // Expected. } }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_OB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;//from w w w. ja v a2 s . c o m String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); stream.close(); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_PC_OB() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;// w ww .jav a2 s . c o m String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 4); assertThat(text, is("0123456789")); stream.close(); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_FC_IB__C1_XC__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;/*from w ww . java2 s. c o m*/ String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); stream.close(); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_FC_IB__C1_XC__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;//ww w. j av a 2 s . co m String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 3); assertThat(text, is("0123456789")); stream.close(); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 3); assertThat(text, is("0123456789")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_IB__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; InputStream stream;/*from w w w.j av a 2s . co m*/ String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, 4); assertThat(text, is("0123")); stream.close(); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); }