2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util;
21 /* ------------------------------------------------------------ */
25 * This class wraps a standard {@link java.lang.StringBuffer} and provides methods to append
26 * UTF-8 encoded bytes, that are converted into characters.
28 * This class is stateful and up to 4 calls to {@link #append(byte)} may be needed before
29 * state a character is appended to the string buffer.
31 * The UTF-8 decoding is done by this class and no additional buffers or Readers are used.
32 * The UTF-8 code was inspired by http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
34 public class Utf8StringBuffer extends Utf8Appendable
36 final StringBuffer _buffer;
38 public Utf8StringBuffer()
40 super(new StringBuffer());
41 _buffer = (StringBuffer)_appendable;
44 public Utf8StringBuffer(int capacity)
46 super(new StringBuffer(capacity));
47 _buffer = (StringBuffer)_appendable;
53 return _buffer.length();
63 public StringBuffer getStringBuffer()
70 public String toString()
73 return _buffer.toString();