@Override public String toString() { return sb.toString(); } }
public ExceptionDrivenStringBuilder append(char ch) { try { buffer[length++] = ch; } catch (ArrayIndexOutOfBoundsException ex) { ensureCapacity(length); buffer[length - 1] = ch; } catch (IndexOutOfBoundsException ex) { buffer[length - 1] = ch; return append(ch); } return this; }
public ExceptionDrivenStringBuilder replace(char a, char b) { return replace(a, b, 0, length); }
requestBuilder.append(request.method().name()) .append(" ").append(sb -> rewritePath(sb, request.path(), request.getQueryString())) .append(" HTTP/1.1\r\n") .append("Host: ").append(host) .append(sb -> { if (port != 80) sb.append(":").append(port); }).append("\r\n") .append("X-Real-IP: ").append(request.connection().getIp()).append("\r\n") .append("X-Forwarded-for: ").append(request.connection().getServer().getHostname()).append("\r\n"); requestBuilder.append(header.getKey()).append(": ").append(header.getValue().getValue()).append("\r\n"); else for (String value : header.getValue().getValues()) requestBuilder.append(header.getKey()).append(": ").append(value).append("\r\n"); requestBuilder.append("\r\n"); finalConnection.write(AsciiReader.write(requestBuilder.toString()), (ByteBufferProvider) Thread.currentThread());
@Test public void test_toString() { ExceptionDrivenStringBuilder sb = new ExceptionDrivenStringBuilder(); new Path().add("/foo//bar").toString(sb); Assert.assertEquals("/foo/bar", sb.toString()); } }
public void setLength(int length) { ensureCapacity(length); this.length = length; }
public ExceptionDrivenStringBuilder clear() { setLength(0); return this; }
@Test public void appendersTests() { Appender appender; appender = Appender.create(new StringBuilder()); Assert.assertEquals(appendData(appender), appender.toString()); appender = Appender.create(new ExceptionDrivenStringBuilder()); Assert.assertEquals(appendData(appender), appender.toString()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); appender = Appender.create(outputStream); Assert.assertEquals(appendData(appender), new String(outputStream.toByteArray())); outputStream.reset(); appender = Appender.create(new OutputStreamWriter(outputStream)); Assert.assertEquals(appendData(appender), new String(outputStream.toByteArray())); testException(Appender.create(new PipedOutputStream()), "Pipe not connected"); testException(Appender.create(new OutputStreamWriter(new PipedOutputStream())), "Pipe not connected"); }
public int lastIndexOf(String str) { return lastIndexOf(str, length); }
@Override public Renderer append(char ch) { sb.append(ch); return this; } };
public void setLength(int length) { ensureCapacity(length); this.length = length; }
public ExceptionDrivenStringBuilder clear() { setLength(0); return this; }
public ExceptionDrivenStringBuilder append(char ch) { try { buffer[length++] = ch; } catch (ArrayIndexOutOfBoundsException ex) { ensureCapacity(length); buffer[length - 1] = ch; } catch (IndexOutOfBoundsException ex) { buffer[length - 1] = ch; return append(ch); } return this; }
@Override public Renderer append(String s) { sb.append(s); return this; }
@Override public String map(ExceptionDrivenStringBuilder builder) { serialize(src, builder, context); return builder.toString(); } });
public ExceptionDrivenStringBuilder replace(int start, int end, String str) { if (start < 0) throw new StringIndexOutOfBoundsException(start); if (start > length) throw new StringIndexOutOfBoundsException("start > length()"); if (start > end) throw new StringIndexOutOfBoundsException("start > end"); if (end > length) end = length; int len = str.length(); int newLength = length + len - (end - start); ensureCapacity(newLength); System.arraycopy(buffer, end, buffer, start + len, length - end); str.getChars(0, len, buffer, start); length = newLength; return this; }
public ExceptionDrivenStringBuilder replace(char a, char b) { return replace(a, b, 0, length); }
public ExceptionDrivenStringBuilder append(char[] chars, int from, int length) { try { System.arraycopy(chars, from, buffer, this.length, length); } catch (ArrayIndexOutOfBoundsException ex) { ensureCapacity(length + this.length); return append(chars, from, length); } catch (IndexOutOfBoundsException ex) { ensureCapacity(length + this.length); return append(chars, from, length); } this.length += length; return this; }