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;
22 /* ------------------------------------------------------------ */
23 /** UTF-8 StringBuilder.
25 * This class wraps a standard {@link java.lang.StringBuilder} 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/
35 public class Utf8StringBuilder extends Utf8Appendable
37 final StringBuilder _buffer;
39 public Utf8StringBuilder()
41 super(new StringBuilder());
42 _buffer=(StringBuilder)_appendable;
45 public Utf8StringBuilder(int capacity)
47 super(new StringBuilder(capacity));
48 _buffer=(StringBuilder)_appendable;
54 return _buffer.length();
64 public StringBuilder getStringBuilder()
71 public String toString()
74 return _buffer.toString();