/** * Turns the given two strings (with widths) and spacer into a formatted * two-column string. * * @param s1 {@code non-null;} first string * @param width1 {@code > 0;} width of the first column * @param spacer {@code non-null;} spacer string * @param s2 {@code non-null;} second string * @param width2 {@code > 0;} width of the second column * @return {@code non-null;} an appropriately-formatted string */ public static String toString(String s1, int width1, String spacer, String s2, int width2) { int len1 = s1.length(); int len2 = s2.length(); StringWriter sw = new StringWriter((len1 + len2) * 3); TwoColumnOutput twoOut = new TwoColumnOutput(sw, width1, width2, spacer); try { twoOut.getLeft().write(s1); twoOut.getRight().write(s2); } catch (IOException ex) { throw new RuntimeException("shouldn't happen", ex); } twoOut.flush(); return sw.toString(); }
/** * Flushes the output. If there are more lines of pending output in one * column, then the other column will get filled with blank lines. */ public void flush() { try { appendNewlineIfNecessary(leftBuf, leftColumn); appendNewlineIfNecessary(rightBuf, rightColumn); outputFullLines(); flushLeft(); flushRight(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Flushes the right column buffer, printing it and clearing the buffer. * If the buffer is already empty, this does nothing. */ private void flushRight() throws IOException { appendNewlineIfNecessary(rightBuf, rightColumn); while (rightBuf.length() != 0) { leftColumn.write('\n'); outputFullLines(); } }
/** * Returns the string form of this instance suitable for inclusion in * a human-oriented listing dump. This method will return {@code null} * if this instance should not appear in a listing. * * @param prefix {@code non-null;} prefix before the address; each follow-on * line will be indented to match as well * @param width {@code width >= 0;} the width of the output or {@code 0} for * unlimited width * @param noteIndices whether to include an explicit notation of * constant pool indices * @return {@code null-ok;} the string form or {@code null} if this * instance should not appear in a listing */ public final String listingString(String prefix, int width, boolean noteIndices) { String insnPerSe = listingString0(noteIndices); if (insnPerSe == null) { return null; } String addr = prefix + identifierString() + ": "; int w1 = addr.length(); int w2 = (width == 0) ? insnPerSe.length() : (width - w1); return TwoColumnOutput.toString(addr, w1, "", insnPerSe, w2); }
/** * Outputs to the final destination as many full line pairs as * there are in the pending output, removing those lines from * their respective buffers. This method terminates when at * least one of the two column buffers is empty. */ private void outputFullLines() throws IOException { for (;;) { int leftLen = leftBuf.indexOf("\n"); if (leftLen < 0) { return; } int rightLen = rightBuf.indexOf("\n"); if (rightLen < 0) { return; } if (leftLen != 0) { out.write(leftBuf.substring(0, leftLen)); } if (rightLen != 0) { writeSpaces(out, leftWidth - leftLen); out.write(rightBuf.substring(0, rightLen)); } out.write('\n'); leftBuf.delete(0, leftLen + 1); rightBuf.delete(0, rightLen + 1); } }
/** * Flushes the right column buffer, printing it and clearing the buffer. * If the buffer is already empty, this does nothing. */ private void flushRight() throws IOException { appendNewlineIfNecessary(rightBuf, rightColumn); while (rightBuf.length() != 0) { leftColumn.write('\n'); outputFullLines(); } }
/** * Returns the string form of this instance suitable for inclusion in * a human-oriented listing dump. This method will return {@code null} * if this instance should not appear in a listing. * * @param prefix {@code non-null;} prefix before the address; each follow-on * line will be indented to match as well * @param width {@code >= 0;} the width of the output or {@code 0} for * unlimited width * @param noteIndices whether to include an explicit notation of * constant pool indices * @return {@code null-ok;} the string form or {@code null} if this * instance should not appear in a listing */ public final String listingString(String prefix, int width, boolean noteIndices) { String insnPerSe = listingString0(noteIndices); if (insnPerSe == null) { return null; } String addr = prefix + identifierString() + ": "; int w1 = addr.length(); int w2 = (width == 0) ? insnPerSe.length() : (width - w1); return TwoColumnOutput.toString(addr, w1, "", insnPerSe, w2); }
/** * Outputs to the final destination as many full line pairs as * there are in the pending output, removing those lines from * their respective buffers. This method terminates when at * least one of the two column buffers is empty. */ private void outputFullLines() throws IOException { for (;;) { int leftLen = leftBuf.indexOf("\n"); if (leftLen < 0) { return; } int rightLen = rightBuf.indexOf("\n"); if (rightLen < 0) { return; } if (leftLen != 0) { out.write(leftBuf.substring(0, leftLen)); } if (rightLen != 0) { writeSpaces(out, leftWidth - leftLen); out.write(rightBuf.substring(0, rightLen)); } out.write('\n'); leftBuf.delete(0, leftLen + 1); rightBuf.delete(0, rightLen + 1); } }
/** * Turns the given two strings (with widths) and spacer into a formatted * two-column string. * * @param s1 {@code non-null;} first string * @param width1 {@code > 0;} width of the first column * @param spacer {@code non-null;} spacer string * @param s2 {@code non-null;} second string * @param width2 {@code > 0;} width of the second column * @return {@code non-null;} an appropriately-formatted string */ public static String toString(String s1, int width1, String spacer, String s2, int width2) { int len1 = s1.length(); int len2 = s2.length(); StringWriter sw = new StringWriter((len1 + len2) * 3); TwoColumnOutput twoOut = new TwoColumnOutput(sw, width1, width2, spacer); try { twoOut.getLeft().write(s1); twoOut.getRight().write(s2); } catch (IOException ex) { throw new RuntimeException("shouldn't happen", ex); } twoOut.flush(); return sw.toString(); }
/** * Flushes the output. If there are more lines of pending output in one * column, then the other column will get filled with blank lines. */ public void flush() { try { appendNewlineIfNecessary(leftBuf, leftColumn); appendNewlineIfNecessary(rightBuf, rightColumn); outputFullLines(); flushLeft(); flushRight(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Flushes the left column buffer, printing it and clearing the buffer. * If the buffer is already empty, this does nothing. */ private void flushLeft() throws IOException { appendNewlineIfNecessary(leftBuf, leftColumn); while (leftBuf.length() != 0) { rightColumn.write('\n'); outputFullLines(); } }
/** * Returns the string form of this instance suitable for inclusion in * a human-oriented listing dump. This method will return {@code null} * if this instance should not appear in a listing. * * @param prefix {@code non-null;} prefix before the address; each follow-on * line will be indented to match as well * @param width {@code >= 0;} the width of the output or {@code 0} for * unlimited width * @param noteIndices whether to include an explicit notation of * constant pool indices * @return {@code null-ok;} the string form or {@code null} if this * instance should not appear in a listing */ public final String listingString(String prefix, int width, boolean noteIndices) { String insnPerSe = listingString0(noteIndices); if (insnPerSe == null) { return null; } String addr = prefix + identifierString() + ": "; int w1 = addr.length(); int w2 = (width == 0) ? insnPerSe.length() : (width - w1); return TwoColumnOutput.toString(addr, w1, "", insnPerSe, w2); }
/** * Outputs to the final destination as many full line pairs as * there are in the pending output, removing those lines from * their respective buffers. This method terminates when at * least one of the two column buffers is empty. */ private void outputFullLines() throws IOException { for (;;) { int leftLen = leftBuf.indexOf("\n"); if (leftLen < 0) { return; } int rightLen = rightBuf.indexOf("\n"); if (rightLen < 0) { return; } if (leftLen != 0) { out.write(leftBuf.substring(0, leftLen)); } if (rightLen != 0) { writeSpaces(out, leftWidth - leftLen); out.write(rightBuf.substring(0, rightLen)); } out.write('\n'); leftBuf.delete(0, leftLen + 1); rightBuf.delete(0, rightLen + 1); } }
/** * Turns the given two strings (with widths) and spacer into a formatted * two-column string. * * @param s1 {@code non-null;} first string * @param width1 {@code > 0;} width of the first column * @param spacer {@code non-null;} spacer string * @param s2 {@code non-null;} second string * @param width2 {@code > 0;} width of the second column * @return {@code non-null;} an appropriately-formatted string */ public static String toString(String s1, int width1, String spacer, String s2, int width2) { int len1 = s1.length(); int len2 = s2.length(); StringWriter sw = new StringWriter((len1 + len2) * 3); TwoColumnOutput twoOut = new TwoColumnOutput(sw, width1, width2, spacer); try { twoOut.getLeft().write(s1); twoOut.getRight().write(s2); } catch (IOException ex) { throw new RuntimeException("shouldn't happen", ex); } twoOut.flush(); return sw.toString(); }
/** * Flushes the output. If there are more lines of pending output in one * column, then the other column will get filled with blank lines. */ public void flush() { try { appendNewlineIfNecessary(leftBuf, leftColumn); appendNewlineIfNecessary(rightBuf, rightColumn); outputFullLines(); flushLeft(); flushRight(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * Flushes the right column buffer, printing it and clearing the buffer. * If the buffer is already empty, this does nothing. */ private void flushRight() throws IOException { appendNewlineIfNecessary(rightBuf, rightColumn); while (rightBuf.length() != 0) { leftColumn.write('\n'); outputFullLines(); } }
/** * Returns the string form of this instance suitable for inclusion in * a human-oriented listing dump. This method will return {@code null} * if this instance should not appear in a listing. * * @param prefix {@code non-null;} prefix before the address; each follow-on * line will be indented to match as well * @param width {@code >= 0;} the width of the output or {@code 0} for * unlimited width * @param noteIndices whether to include an explicit notation of * constant pool indices * @return {@code null-ok;} the string form or {@code null} if this * instance should not appear in a listing */ public final String listingString(String prefix, int width, boolean noteIndices) { String insnPerSe = listingString0(noteIndices); if (insnPerSe == null) { return null; } String addr = prefix + identifierString() + ": "; int w1 = addr.length(); int w2 = (width == 0) ? insnPerSe.length() : (width - w1); return TwoColumnOutput.toString(addr, w1, "", insnPerSe, w2); }
/** * Outputs to the final destination as many full line pairs as * there are in the pending output, removing those lines from * their respective buffers. This method terminates when at * least one of the two column buffers is empty. */ private void outputFullLines() throws IOException { for (;;) { int leftLen = leftBuf.indexOf("\n"); if (leftLen < 0) { return; } int rightLen = rightBuf.indexOf("\n"); if (rightLen < 0) { return; } if (leftLen != 0) { out.write(leftBuf.substring(0, leftLen)); } if (rightLen != 0) { writeSpaces(out, leftWidth - leftLen); out.write(rightBuf.substring(0, rightLen)); } out.write('\n'); leftBuf.delete(0, leftLen + 1); rightBuf.delete(0, rightLen + 1); } }
/** * Turns the given two strings (with widths) and spacer into a formatted * two-column string. * * @param s1 {@code non-null;} first string * @param width1 {@code > 0;} width of the first column * @param spacer {@code non-null;} spacer string * @param s2 {@code non-null;} second string * @param width2 {@code > 0;} width of the second column * @return {@code non-null;} an appropriately-formatted string */ public static String toString(String s1, int width1, String spacer, String s2, int width2) { int len1 = s1.length(); int len2 = s2.length(); StringWriter sw = new StringWriter((len1 + len2) * 3); TwoColumnOutput twoOut = new TwoColumnOutput(sw, width1, width2, spacer); try { twoOut.getLeft().write(s1); twoOut.getRight().write(s2); } catch (IOException ex) { throw new RuntimeException("shouldn't happen", ex); } twoOut.flush(); return sw.toString(); }
/** * Flushes the output. If there are more lines of pending output in one * column, then the other column will get filled with blank lines. */ public void flush() { try { appendNewlineIfNecessary(leftBuf, leftColumn); appendNewlineIfNecessary(rightBuf, rightColumn); outputFullLines(); flushLeft(); flushRight(); } catch (IOException ex) { throw new RuntimeException(ex); } }