Example usage for org.apache.http.entity BasicHttpEntity setContent

List of usage examples for org.apache.http.entity BasicHttpEntity setContent

Introduction

In this page you can find the example usage for org.apache.http.entity BasicHttpEntity setContent.

Prototype

public void setContent(InputStream inputStream) 

Source Link

Usage

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_FC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/* w  ww  . java2s. c  o m*/
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(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.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;//  www.j a v  a2  s  .  c  om
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(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"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_PC_IB__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*  w w w.  j  a v  a  2s  .  c om*/
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);

    stream = replay.getContent();
    text = blockRead(stream, UTF8, 4, 1);
    assertThat(text, is("0123"));
    stream.close();

    stream = replay.getContent();
    text = blockRead(stream, UTF8, -1, 7);
    assertThat(text, is("0123456789"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*w w w .  j a v  a  2s  . c om*/
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);

    stream = replay.getContent();
    text = byteRead(stream, 7);
    assertThat(text, is("0123456"));
    stream.close();

    stream = replay.getContent();
    text = byteRead(stream, -1);
    assertThat(text, is("0123456789"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_PC_IB__C1_XC__C2_FC() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*  w  w w . j  av a  2s .c  o m*/
    InputStream stream;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);

    stream = replay.getContent();
    text = blockRead(stream, UTF8, 7, 2);
    assertThat(text, is("0123456"));
    stream.close();

    stream = replay.getContent();
    text = blockRead(stream, UTF8, -1, 7);
    assertThat(text, is("0123456789"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C2_PC_OB__C1_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;//from  w  ww.j ava 2s.c om
    InputStream stream1, stream2;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 5);

    stream1 = replay.getContent();
    text = byteRead(stream1, 3);
    assertThat(text, is("012"));

    stream2 = replay.getContent();
    text = byteRead(stream2, 5);
    assertThat(text, is("01234"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_PC_IB__C2_PC_IB__C2_PC_IB() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*w  ww . jav a  2 s . c o m*/
    InputStream stream1, stream2;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);
    stream1 = replay.getContent();
    text = blockRead(stream1, UTF8, 3, 2);
    assertThat(text, is("012"));

    stream2 = replay.getContent();
    text = blockRead(stream2, UTF8, 4, 3);
    assertThat(text, is("0123"));

    text = blockRead(stream1, UTF8, 3, 2);
    assertThat(text, is("345"));
}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testS_C1_PC_IB__C2_PC_IB__C2_PC_IB() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*from ww w . j  a v  a  2  s .c  om*/
    InputStream stream1, stream2;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 20);

    stream1 = replay.getContent();
    text = byteRead(stream1, 3);
    assertThat(text, is("012"));

    stream2 = replay.getContent();
    text = byteRead(stream2, 4);
    assertThat(text, is("0123"));

    text = byteRead(stream1, 3);
    assertThat(text, is("345"));
}

From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java

public void postAndRecieve(String method, String URL, ArrayList<BasicHeader> headers, String body,
        boolean authenticate) throws IOException {
    BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(method, URL);

    BasicHeader head = null;//from ww  w .  j  ava2s  .c  o  m
    BasicHeader h2 = null;
    if (authenticate) {
        head = new BasicHeader("ID", server.getLogin());
        h2 = new BasicHeader("Password", server.getPassword());
    }
    BasicHttpEntity entity = new BasicHttpEntity();
    if (body != null) {
        InputStream in = null;
        Log.i("Android Mobile Voting", "loading entity");
        try {
            in = new ByteArrayInputStream(body.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e1) {
            e1.printStackTrace();
        }

        entity.setContent(in);
        request.setEntity(entity);
    }
    request.addHeader(head);
    request.addHeader(h2);

    if (headers != null) {
    }

    HttpHost g = new HttpHost(server.getAddress(), port, usingScheme);
    connection.execute(g, request);

    Log.e("Android Mobile Voting", "sending");

}

From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java

@Test
public void testB_C1_PC_IB__C2_PC_OB__C1_AC__EE() throws IOException {
    String data = "0123456789";
    BasicHttpEntity basic;
    CappedBufferHttpEntity replay;/*  www.  j a va2 s .c  o m*/
    InputStream stream1, stream2;
    String text;

    basic = new BasicHttpEntity();
    basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8)));
    replay = new CappedBufferHttpEntity(basic, 5);

    stream1 = replay.getContent();
    text = blockRead(stream1, UTF8, 3, 2);
    assertThat(text, is("012"));

    stream2 = replay.getContent();
    try {
        text = blockRead(stream2, UTF8, 6, 4);
        fail("expected IOException");
    } catch (IOException e) {
        // expected
    }

}