Package org.apache.http.util

Examples of org.apache.http.util.CharArrayBuffer


    public void testNetscapeCookieParsing() throws Exception {
        NetscapeDraftHeaderParser parser = NetscapeDraftHeaderParser.DEFAULT;
       
        String s =
            "name  = value; test; test1 =  stuff,with,commas   ; test2 =  \"stuff; stuff\"; test3=\"stuff";
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append(s);
        ParserCursor cursor = new ParserCursor(0, s.length());
       
        HeaderElement he = parser.parseHeader(buffer, cursor);
        assertEquals("name", he.getName());
        assertEquals("value", he.getValue());
        NameValuePair[] params = he.getParameters();
        assertEquals("test", params[0].getName());
        assertEquals(null, params[0].getValue());
        assertEquals("test1", params[1].getName());
        assertEquals("stuff,with,commas", params[1].getValue());
        assertEquals("test2", params[2].getName());
        assertEquals("stuff; stuff", params[2].getValue());
        assertEquals("test3", params[3].getName());
        assertEquals("\"stuff", params[3].getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());

        s = "  ";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
        he = parser.parseHeader(buffer, cursor);
        assertEquals("", he.getName());
        assertEquals(null, he.getValue());
    }
View Full Code Here


        buffer.append("and stuff like that");
        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            transmitter.writeLine(chbuffer);
        }
        //these write operations should have no effect
        transmitter.writeLine((String)null);
        transmitter.writeLine((CharArrayBuffer)null);
View Full Code Here

        buffer.append("and stuff like that");
        teststrs[2] = buffer.toString();
        teststrs[3] = "";
        teststrs[4] = "And goodbye";
       
        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup();
        for (int i = 0; i < teststrs.length; i++) {
            chbuffer.clear();
            chbuffer.append(teststrs[i]);
            transmitter.writeLine(chbuffer);
        }
        //these write operations should have no effect
        transmitter.writeLine((String)null);
        transmitter.writeLine((CharArrayBuffer)null);
View Full Code Here

        HttpParams params = new BasicHttpParams(null);
        HttpProtocolParams.setHttpElementCharset(params, "UTF-8");
       
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup(params);

        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        for (int i = 0; i < 10; i++) {
            chbuffer.clear();
            chbuffer.append(s1);
            transmitter.writeLine(chbuffer);
            chbuffer.clear();
            chbuffer.append(s2);
            transmitter.writeLine(chbuffer);
            chbuffer.clear();
            chbuffer.append(s3);
            transmitter.writeLine(chbuffer);
        }
        transmitter.flush();
        long writedBytes = transmitter.getMetrics().getBytesTransferred();
        long expBytes = ((s1.toString().getBytes("UTF-8").length + 2)+
View Full Code Here

        HttpParams params = new BasicHttpParams(null);
        HttpProtocolParams.setHttpElementCharset(params, HTTP.ISO_8859_1);
       
        HttpDataTransmitterMockup transmitter = new HttpDataTransmitterMockup(params);

        CharArrayBuffer chbuffer = new CharArrayBuffer(16);
        for (int i = 0; i < 10; i++) {
            chbuffer.clear();
            chbuffer.append(s1);
            transmitter.writeLine(chbuffer);
        }
        transmitter.flush();
        long writedBytes = transmitter.getMetrics().getBytesTransferred();
        long expBytes = ((s1.toString().getBytes(HTTP.ISO_8859_1).length + 2)) * 10;
 
View Full Code Here

    public static Test suite() {
        return new TestSuite(TestCharArrayBuffer.class);
    }

    public void testConstructor() throws Exception {
      CharArrayBuffer buffer = new CharArrayBuffer(16);
      assertEquals(16, buffer.capacity());
      assertEquals(0, buffer.length());
        assertNotNull(buffer.buffer());
        assertEquals(16, buffer.buffer().length);
      try {
        new CharArrayBuffer(-1);
        fail("IllegalArgumentException should have been thrown");
      } catch (IllegalArgumentException ex) {
        // expected
      }
    }
View Full Code Here

        // expected
      }
    }
   
    public void testSimpleAppend() throws Exception {
      CharArrayBuffer buffer = new CharArrayBuffer(16);
      assertEquals(16, buffer.capacity());
      assertEquals(0, buffer.length());
      char[] b1 = buffer.toCharArray();
      assertNotNull(b1);
      assertEquals(0, b1.length);
      assertTrue(buffer.isEmpty());
        assertFalse(buffer.isFull());
     
      char[] tmp = new char[] { '1', '2', '3', '4'};
      buffer.append(tmp, 0, tmp.length);
      assertEquals(16, buffer.capacity());
      assertEquals(4, buffer.length());
      assertFalse(buffer.isEmpty());
        assertFalse(buffer.isFull());
     
      char[] b2 = buffer.toCharArray();
      assertNotNull(b2);
      assertEquals(4, b2.length);
      for (int i = 0; i < tmp.length; i++) {
          assertEquals(tmp[i], b2[i]);
          assertEquals(tmp[i], buffer.charAt(i));
      }
      assertEquals("1234", buffer.toString());
     
      buffer.clear();
      assertEquals(16, buffer.capacity());
      assertEquals(0, buffer.length());
      assertTrue(buffer.isEmpty());
        assertFalse(buffer.isFull());
    }
View Full Code Here

      assertTrue(buffer.isEmpty());
        assertFalse(buffer.isFull());
    }
   
    public void testExpandAppend() throws Exception {
      CharArrayBuffer buffer = new CharArrayBuffer(4);
      assertEquals(4, buffer.capacity());
     
      char[] tmp = new char[] { '1', '2', '3', '4'};
      buffer.append(tmp, 0, 2);
      buffer.append(tmp, 0, 4);
      buffer.append(tmp, 0, 0);

      assertEquals(8, buffer.capacity());
      assertEquals(6, buffer.length());
     
      buffer.append(tmp, 0, 4);
     
      assertEquals(16, buffer.capacity());
      assertEquals(10, buffer.length());
     
      assertEquals("1212341234", buffer.toString());
    }
View Full Code Here

     
      assertEquals("1212341234", buffer.toString());
    }

    public void testAppendString() throws Exception {
      CharArrayBuffer buffer = new CharArrayBuffer(8);
      buffer.append("stuff");
      buffer.append(" and more stuff");
      assertEquals("stuff and more stuff", buffer.toString());
    }
View Full Code Here

      buffer.append(" and more stuff");
      assertEquals("stuff and more stuff", buffer.toString());
    }
   
    public void testAppendNullString() throws Exception {
      CharArrayBuffer buffer = new CharArrayBuffer(8);
      buffer.append((String)null);
      assertEquals("null", buffer.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.util.CharArrayBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.