public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } // Ignores the leftover spaces if the cell is the last of the column. if (!isLast) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } } } }
pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n"); pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n");
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { boolean helpWanted = request.paramAsBoolean("help", false); if (helpWanted) { return channel -> { Table table = getTableWithHeader(request); int[] width = buildHelpWidths(table, request); BytesStream bytesOutput = Streams.flushOnCloseStream(channel.bytesOutput()); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput); for (Table.Cell cell : table.getHeaders()) { // need to do left-align always, so create new cells pad(new Table.Cell(cell.value), width[0], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out); out.append("\n"); } out.close(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes())); }; } else { return doCatRequest(request, client); } }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } for (byte i = 0; i < leftOver; i++) { out.append(" "); } } }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } for (byte i = 0; i < leftOver; i++) { out.append(" "); } } }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } // Ignores the leftover spaces if the cell is the last of the column. if (!isLast) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } } } }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } // Ignores the leftover spaces if the cell is the last of the column. if (!isLast) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } } } }
public static void pad(Table.Cell cell, int width, RestRequest request, UTF8StreamWriter out, boolean isLast) throws IOException { String sValue = renderValue(request, cell.value); int length = sValue == null ? 0 : sValue.length(); byte leftOver = (byte) (width - length); String textAlign = cell.attr.get("text-align"); if (textAlign == null) { textAlign = "left"; } if (leftOver > 0 && textAlign.equals("right")) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } if (sValue != null) { out.append(sValue); } } else { if (sValue != null) { out.append(sValue); } // Ignores the leftover spaces if the cell is the last of the column. if (!isLast) { for (byte i = 0; i < leftOver; i++) { out.append(" "); } } } }
public static RestResponse buildTextPlainResponse(Table table, RestChannel channel) throws IOException { RestRequest request = channel.request(); boolean verbose = request.paramAsBoolean("v", false); List<DisplayHeader> headers = buildDisplayHeaders(table, request); int[] width = buildWidths(table, request, verbose, headers); try (BytesStreamOutput bytesOut = channel.bytesOutput(); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut)) { if (verbose) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out); out.append("\t\t"); } out.append("\n"); } for (int row = 0; row < table.getRows().size(); row++) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); pad(table.getAsMap().get(header.name).get(row), width[col], request, out); out.append("\t\t"); } out.append("\n"); } return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes()); } }
public static RestResponse buildTextPlainResponse(Table table, RestChannel channel) throws IOException { RestRequest request = channel.request(); boolean verbose = request.paramAsBoolean("v", false); List<DisplayHeader> headers = buildDisplayHeaders(table, request); int[] width = buildWidths(table, request, verbose, headers); BytesStreamOutput bytesOut = channel.bytesOutput(); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOut); if (verbose) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out); out.append(" "); } out.append("\n"); } for (int row = 0; row < table.getRows().size(); row++) { for (int col = 0; col < headers.size(); col++) { DisplayHeader header = headers.get(col); pad(table.getAsMap().get(header.name).get(row), width[col], request, out); out.append(" "); } out.append("\n"); } out.close(); return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes()); }
pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n"); pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n");
pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n"); pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n");
pad(new Table.Cell(header.display, table.findHeaderByName(header.name)), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n"); pad(table.getAsMap().get(header.name).get(row), width[col], request, out, isLastColumn); if (!isLastColumn) { out.append(" "); out.append("\n");
public static RestResponse response(RestChannel channel, String text) throws IOException { try (UTF8StreamWriter out = new UTF8StreamWriter(); BytesStreamOutput bytesOut = channel.bytesOutput()) { out.setOutput(bytesOut); out.append(text); return new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOut.bytes()); } }
@Override public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) throws Exception { boolean helpWanted = request.paramAsBoolean("help", false); if (helpWanted) { Table table = getTableWithHeader(request); int[] width = buildHelpWidths(table, request); BytesStreamOutput bytesOutput = channel.bytesOutput(); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput); for (Table.Cell cell : table.getHeaders()) { // need to do left-align always, so create new cells pad(new Table.Cell(cell.value), width[0], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out); out.append("\n"); } out.close(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes())); } else { doRequest(request, channel, client); } } }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { boolean helpWanted = request.paramAsBoolean("help", false); if (helpWanted) { return channel -> { Table table = getTableWithHeader(request); int[] width = buildHelpWidths(table, request); BytesStream bytesOutput = Streams.flushOnCloseStream(channel.bytesOutput()); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput); for (Table.Cell cell : table.getHeaders()) { // need to do left-align always, so create new cells pad(new Table.Cell(cell.value), width[0], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out); out.append("\n"); } out.close(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes())); }; } else { return doCatRequest(request, client); } }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { boolean helpWanted = request.paramAsBoolean("help", false); if (helpWanted) { return channel -> { Table table = getTableWithHeader(request); int[] width = buildHelpWidths(table, request); BytesStream bytesOutput = Streams.flushOnCloseStream(channel.bytesOutput()); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput); for (Table.Cell cell : table.getHeaders()) { // need to do left-align always, so create new cells pad(new Table.Cell(cell.value), width[0], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out); out.append("\n"); } out.close(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes())); }; } else { return doCatRequest(request, client); } }
@Override public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { boolean helpWanted = request.paramAsBoolean("help", false); if (helpWanted) { return channel -> { Table table = getTableWithHeader(request); int[] width = buildHelpWidths(table, request); BytesStream bytesOutput = Streams.flushOnCloseStream(channel.bytesOutput()); UTF8StreamWriter out = new UTF8StreamWriter().setOutput(bytesOutput); for (Table.Cell cell : table.getHeaders()) { // need to do left-align always, so create new cells pad(new Table.Cell(cell.value), width[0], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("alias") ? cell.attr.get("alias") : ""), width[1], request, out); out.append(" | "); pad(new Table.Cell(cell.attr.containsKey("desc") ? cell.attr.get("desc") : "not available"), width[2], request, out); out.append("\n"); } out.close(); channel.sendResponse(new BytesRestResponse(RestStatus.OK, BytesRestResponse.TEXT_CONTENT_TYPE, bytesOutput.bytes())); }; } else { return doCatRequest(request, client); } }