@Override public void write(char[] cbuf, int off, int len) throws IOException { for (int i=0; i<len; i++) { write(cbuf[i+off]); } }
try { StringWriter stringWriter = new StringWriter(); WrappedIndentingWriter writer = new WrappedIndentingWriter(stringWriter, width - 5, width); writer.write("usage:"); writer.indent(2); writer.write(" "); writer.write(ExtendedCommands.commandName(jc)); for (ParameterDescription param : leafJc.getParameters()) { if (!param.getParameter().hidden()) { writer.write(" ["); writer.write(param.getParameter().getParameter().names()[0]); writer.write("]"); writer.write(" [<options>]"); writer.write(" [<command [<args>]]"); String[] argumentNames = ExtendedCommands.parameterArgumentNames(leafJc.getMainParameter()); if (argumentNames.length == 0) { writer.write(" <args>"); } else { String argumentName = argumentNames[0]; boolean writeAngleBrackets = !argumentName.startsWith("<") && !argumentName.startsWith("["); writer.write(" "); if (writeAngleBrackets) { writer.write("<");
private void wrapLine() throws IOException { List<String> wrapped = Lists.newArrayList(StringWrapper.wrapStringOnBreaks(line.toString(), maxWidth)); out.write(wrapped.get(0), 0, wrapped.get(0).length()); out.write('\n'); line.replace(0, line.length(), ""); writeIndent(); for (int i=1; i<wrapped.size(); i++) { if (i > 1) { write('\n'); } write(wrapped.get(i)); } }
@Override public void write(int c) throws IOException { if (c == '\n') { out.write(line.toString()); out.write(c); line.replace(0, line.length(), ""); writeIndent(); } else { line.append((char)c); if (line.length() > maxWidth) { wrapLine(); } } }
/** * Constructs an instance. * * @param out non-null; writer to send final output to * @param width >= 0; the maximum output width (not including * <code>prefix</code>), or <code>0</code> for no maximum * @param prefix non-null; the prefix for each line */ public WrappedIndentingWriter(Writer out, int width, String prefix) { super(out); if (out == null) { throw new NullPointerException("out == null"); } if (width < 0) { throw new IllegalArgumentException("width < 0"); } if (prefix == null) { throw new NullPointerException("prefix == null"); } this.width = (width != 0) ? width : Integer.MAX_VALUE; this.maxIndent = width >> 1; this.prefix = (prefix.length() == 0) ? null : prefix; bol(); }
private void wrapLine() throws IOException { List<String> wrapped = Lists.newArrayList(StringWrapper.wrapStringOnBreaks(line.toString(), maxWidth)); out.write(wrapped.get(0), 0, wrapped.get(0).length()); out.write('\n'); line.replace(0, line.length(), ""); writeIndent(); for (int i=1; i<wrapped.size(); i++) { if (i > 1) { write('\n'); } write(wrapped.get(i)); } }
@Override public void write(int c) throws IOException { if (c == '\n') { out.write(line.toString()); out.write(c); line.replace(0, line.length(), ""); writeIndent(); } else { line.append((char)c); if (line.length() > maxWidth) { wrapLine(); } } }
bol(); } else { column++;
/** {@inheritDoc} */ @Override public void write(char[] cbuf, int off, int len) throws IOException { synchronized (lock) { while (len > 0) { write(cbuf[off]); off++; len--; } } }
@Override public void write(char[] cbuf, int off, int len) throws IOException { for (int i=0; i<len; i++) { write(cbuf[i+off]); } }
@Override public void write(String str, int off, int len) throws IOException { for (int i=0; i<len; i++) { write(str.charAt(i+off)); } }
/** {@inheritDoc} */ @Override public void write(String str, int off, int len) throws IOException { synchronized (lock) { while (len > 0) { write(str.charAt(off)); off++; len--; } } }
@Override public void write(String str, int off, int len) throws IOException { for (int i=0; i<len; i++) { write(str.charAt(i+off)); } }