List of usage examples for java.lang Character toChars
public static char[] toChars(int codePoint)
From source file:uk.ac.bbsrc.tgac.miso.integration.util.IntegrationUtils.java
/** * Sends a String message to a given host socket * /*w w w . java2s . c o m*/ * @param socket * of type Socket * @param query * of type String * @return String * @throws IntegrationException * when the socket couldn't be created */ public static String sendMessage(Socket socket, String query) throws IntegrationException { BufferedWriter wr = null; BufferedReader rd = null; try { wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8")); // Send data wr.write(query + "\r\n"); wr.flush(); // Get response rd = new BufferedReader(new InputStreamReader(socket.getInputStream())); String line; StringBuilder sb = new StringBuilder(); while ((line = rd.readLine()) != null) { sb.append(line); } wr.close(); rd.close(); String dirty = sb.toString(); StringBuilder response = new StringBuilder(); int codePoint; int i = 0; while (i < dirty.length()) { codePoint = dirty.codePointAt(i); if ((codePoint == 0x9) || (codePoint == 0xA) || (codePoint == 0xD) || ((codePoint >= 0x20) && (codePoint <= 0xD7FF)) || ((codePoint >= 0xE000) && (codePoint <= 0xFFFD)) || ((codePoint >= 0x10000) && (codePoint <= 0x10FFFF))) { response.append(Character.toChars(codePoint)); } i += Character.charCount(codePoint); } return response.toString().replace("\\\n", "").replace("\\\t", ""); } catch (UnknownHostException e) { log.error("Cannot resolve host: " + socket.getInetAddress(), e); throw new IntegrationException(e.getMessage()); } catch (IOException e) { log.error("Couldn't get I/O for the connection to: " + socket.getInetAddress(), e); throw new IntegrationException(e.getMessage()); } finally { try { if (wr != null) { wr.close(); } if (rd != null) { rd.close(); } } catch (Throwable t) { log.error("close socket", t); } } }
From source file:de.vandermeer.asciithemes.u8.U8_NumberingSchemes.java
/** * Numbering scheme using UTF Fullwidth Latin Capital Letter (upper case) characters `-`. * // w ww . j av a 2 s. c o m * ---- * item 1 * item 2 * item 3 * ... * item 26 * ---- * * @return the line */ public static TA_Numbering AlphaFullwidthLatinCapitalLetter() { return new TA_Numbering() { @Override public String getNumber(int number) { Validate.validState(0 < number && number < 27, "numbering supported 0<number<27 - number was: " + number); return new String(Character.toChars(number + 65312)); } @Override public int getMinNumber() { return 1; } @Override public int getMaxNumber() { return 26; } @Override public String getDescription() { return "numbering scheme using UTF Fullwidth Latin Capital Letter (upper case) characters '-'"; } }; }
From source file:org.syncany.plugins.php.PhpTransferManager.java
public String getAnswer(InputStream s, int maxlen) throws Exception { StringBuffer line = new StringBuffer(); int c = s.read(); int t = 1;/*from w ww .j a va2s. c o m*/ while (c != -1 && c != '\n' && t < maxlen) { line.append(Character.toChars(c)); t = t + 1; c = s.read(); } return line.toString(); }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Superscript Latin Small Letter characters. * @param number to convert//from ww w . j a v a2s . c om * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 9) */ public final static String toSuperscript(int number) { if (number < 1 || number > 9) { throw new NotImplementedException( "Arabic literals - UTF Superscript Latin Small Letter - supported 0<number<10 - number was: " + number); } if (number == 1 || number > 3) { //1, 4-10 return new String(Character.toChars(number + 8304)); } else { //2, 3 return new String(Character.toChars(number + 176)); } }
From source file:org.openflexo.technologyadapter.excel.view.ExcelSheetView.java
public ExcelSheetView(ExcelSheet sheet, FlexoController controller) { super(new BorderLayout()); this.sheet = sheet; this.controller = controller; tableModel = new ExcelSheetTableModel(); table = new MultiSpanCellTable(tableModel); table.setBackground(Color.WHITE); table.setShowGrid(true);// w ww . j a v a 2s .c om table.setGridColor(Color.LIGHT_GRAY); table.setRowMargin(0); table.getColumnModel().setColumnMargin(0); for (int i = 0; i < tableModel.getColumnCount(); i++) { TableColumn col = table.getColumnModel().getColumn(i); if (i == 0) { col.setWidth(25); col.setPreferredWidth(25); col.setMinWidth(25); col.setMaxWidth(100); // col.setResizable(false); col.setHeaderValue(null); } else { col.setWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setPreferredWidth(sheet.getSheet().getColumnWidth(i - 1) / 40); col.setHeaderValue("" + Character.toChars(i + 64)[0]); } } table.setDefaultRenderer(Object.class, new ExcelSheetCellRenderer()); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); add(new JScrollPane(table), BorderLayout.CENTER); cellIdentifier = new JTextField(6); cellIdentifier.setEditable(false); cellIdentifier.setHorizontalAlignment(SwingConstants.CENTER); cellValue = new JTextField(); cellValue.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { valueEditedForSelectedCell(cellValue.getText()); } }); /*cellValue.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void insertUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } @Override public void changedUpdate(DocumentEvent e) { valueEditedForSelectedCell(cellValue.getText()); } });*/ JPanel topPanel = new JPanel(new BorderLayout()); topPanel.add(cellIdentifier, BorderLayout.WEST); topPanel.add(cellValue, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { selectionChanged(); } }); table.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnSelectionChanged(ListSelectionEvent e) { selectionChanged(); } @Override public void columnRemoved(TableColumnModelEvent e) { } @Override public void columnMoved(TableColumnModelEvent e) { } @Override public void columnMarginChanged(ChangeEvent e) { } @Override public void columnAdded(TableColumnModelEvent e) { } }); updateRowHeights(); validate(); /*for (Object p : sheet.getSheet().getWorkbook().getAllPictures()) { System.out.println("Picture: " + p); } System.out.println("class = " + sheet.getSheet().getClass()); if (sheet.getSheet() instanceof HSSFSheet) { List<HSSFShape> shapes = ((HSSFSheet) sheet.getSheet()).getDrawingPatriarch().getChildren(); System.out.println("Prout=" + shapes); for (int i = 0; i < shapes.size(); i++) { System.out.println("hop avec " + shapes.get(i)); if (shapes.get(i) instanceof HSSFPicture) { HSSFPicture pic = (HSSFPicture) shapes.get(i); HSSFPictureData picdata = ((HSSFSheet) sheet.getSheet()).getWorkbook().getAllPictures().get(pic.getPictureIndex()); System.out.println("New picture found : " + pic); System.out.println("Anchor : " + pic.getAnchor()); System.out.println("file extension " + picdata.suggestFileExtension()); // int pictureIndex = this.newSheet.getWorkbook().addPicture( picdata.getData(), picdata.getFormat()); // this.newSheet.createDrawingPatriarch().createPicture((HSSFClientAnchor)pic.getAnchor()r, pictureIndex); } } }*/ }
From source file:pl.baczkowicz.spy.formatting.FormattingUtils.java
/** * Replaces characters using the given conversion method. * /*w w w . j a v a 2s. c om*/ * @param conversionMethod The conversion method to be used * @param input The input text * @param fromCharacter From index * @param toCharacter To index * @param wrap Characters to put around the converted text * * @return The converted text */ public static String replaceCharacters(final ConversionMethod conversionMethod, final String input, final int fromCharacter, final int toCharacter, final String wrap) { String convertedText = input; for (int i = fromCharacter; i <= toCharacter; i++) { final String characterToReplace = new String(Character.toChars(i)); if (wrap != null) { convertedText = convertedText.replace(characterToReplace, wrap + convertText(conversionMethod, characterToReplace) + wrap); } else { convertedText = convertedText.replace(characterToReplace, convertText(conversionMethod, characterToReplace)); } } return convertedText; }
From source file:canreg.client.gui.management.CanReg4MigrationInternalFrame.java
@Action private void initActions() { for (int i = 0; i < 10; i++) { String fileName = CR4Path.replaceFirst("C", new String(Character.toChars(67 + i))); if (new File(fileName).exists()) { CR4Path = fileName;//from w ww. ja va 2 s . c om break; } } ssdTask = new SearchSystemDefTask( org.jdesktop.application.Application.getInstance(canreg.client.CanRegClientApp.class), CR4Path); ssdTask.execute(); }
From source file:net.metanotion.json.JsonPath.java
private static Lexeme lexString(final String cs, final int[] position) { final StringBuilder sb = new StringBuilder(); boolean escape = false; while (true) { final int c = read(cs, position); if (c == -1) { throw new IllegalArgumentException("unexpected end of expression in string"); }//www . j a v a2 s.co m final String cbuf = new String(Character.toChars(c)); if (("\'".equals(cbuf)) && !escape) { return new Lexeme(Token.STRING, StringEscapeUtils.unescapeJson(sb.toString())); } else if ("\\".equals(cbuf)) { escape = true; sb.append(cbuf); } else { escape = false; sb.append(cbuf); } } }
From source file:de.vandermeer.asciilist.commons.ArabicLiteralUtils.java
/** * Returns an alphanumeric literal representation of the given number using UTF Subscript characters. * @param number to convert/*from w w w.ja va2 s . c o m*/ * @return alphanumeric literal representation * @throws NotImplementedException if the number is out of bounds (currently smaller than 1 and larger than 9) */ public final static String toSubscript(int number) { if (number < 1 || number > 9) { throw new NotImplementedException( "Arabic literals - UTF Subscript - supported 0<number<10 - number was: " + number); } return new String(Character.toChars(number + 8320)); }
From source file:com.persistent.cloudninja.controller.TenantTaskListController.java
/** * Method added to generate simulated data for bytes sent and received * @return String : Random generated String *//*from w w w .ja v a 2s . c o m*/ @RequestMapping(value = "/showTrafficSimulationPage.htm") public ModelAndView showTrafficsimulation(HttpServletRequest request, HttpServletResponse response, @CookieValue(value = "CLOUDNINJAAUTH", required = false) String cookie) { int START_INDEX = 2; int END_INDEX = 100; TrafficSimulationDTO trafficSimulationDTO = new TrafficSimulationDTO(); if (cookie == null) { cookie = request.getAttribute("cookieNameAttr").toString(); } String tenantId = AuthFilterUtils.getFieldValueFromCookieString(CloudNinjaConstants.COOKIE_TENANTID_PREFIX, cookie); response.addCookie(getTenantLogoCookieInResponse(tenantId, cookie)); Random randomGen = new Random(); int randomNum = randomGen.nextInt(END_INDEX - START_INDEX + 1) + START_INDEX; StringBuilder strbldr = new StringBuilder(); for (int i = 0; i < randomNum; i++) { strbldr.append(Character.toChars((int) (Math.floor(26 * randomGen.nextDouble()) + 65))); } trafficSimulationDTO.setTenantId(tenantId); trafficSimulationDTO.setRandomString(strbldr.toString()); return new ModelAndView("trafficSimulation", "trafficSimulationDTO", trafficSimulationDTO); }