List of usage examples for java.lang Character toString
public String toString()
From source file:org.finra.dm.service.helper.Hive13DdlGenerator.java
/** * Gets the DDL character value based on the specified configured character value. This method supports UTF-8 encoded strings and will "Hive" escape any * non-ASCII printable characters using '\(value)'. * * @param string the configured character value. * @param escapeSingleBackslash specifies if we need to escape a single backslash character with an extra backslash * * @return the DDL character value./*w w w. j a v a2s . c om*/ */ public String getDdlCharacterValue(String string, boolean escapeSingleBackslash) { // Assume the empty string for the return value. StringBuilder returnValueStringBuilder = new StringBuilder(); // If we have an actual character, set the return value based on our rules. if (StringUtils.isNotEmpty(string)) { // Convert the string to UTF-8 so we can the proper characters that were sent via XML. String utf8String = new String(string.getBytes(Charsets.UTF_8), Charsets.UTF_8); // Loop through each character and add each one to the return value. for (int i = 0; i < utf8String.length(); i++) { // Default to the character itself. Character character = string.charAt(i); String nextValue = character.toString(); // If the character isn't ASCII printable, then "Hive" escape it. if (!CharUtils.isAsciiPrintable(character)) { // If the character is unprintable, then display it as the ASCII octal value in \000 format. nextValue = String.format("\\%03o", (int) character); } // Add this character to the return value. returnValueStringBuilder.append(nextValue); } // Check if we need to escape a single backslash character with an extra backslash. if (escapeSingleBackslash && returnValueStringBuilder.toString().equals("\\")) { returnValueStringBuilder.append('\\'); } } // Return the value. return returnValueStringBuilder.toString(); }
From source file:eionet.util.Util.java
/** * XML-escape one character in a string. Does not do it if it looks like * the string is already escaped. Also doesn't escape if the content is * a numeric entity./*from w w w .j av a2s . c o m*/ * * @param pos the position of the character * @param text the string. * @return the escaped character. */ public static String escapeXML(int pos, String text) { if (xmlEscapes == null) { setXmlEscapes(); } Character c = new Character(text.charAt(pos)); for (Enumeration e = xmlEscapes.elements(); e.hasMoreElements();) { String esc = (String) e.nextElement(); if (pos + esc.length() < text.length()) { String sub = text.substring(pos, pos + esc.length()); if (sub.equals(esc)) { return c.toString(); } } } if (pos + 1 < text.length() && text.charAt(pos + 1) == '#') { int semicolonPos = text.indexOf(';', pos + 1); if (semicolonPos != -1) { String sub = text.substring(pos + 2, semicolonPos); if (sub != null) { try { // if the string between # and ; is a number then return true, // because it is most probably an escape sequence if (Integer.parseInt(sub) >= 0) { return c.toString(); } } catch (NumberFormatException nfe) { } } } } String esc = (String) xmlEscapes.get(c); if (esc != null) { return esc; } else { return c.toString(); } }
From source file:com.astir_trotter.atcustom.ui.iconics.core.IconicsDrawable.java
/** * Loads and draws given./*from w w w . java 2 s . c o m*/ * * @param icon * @return The current IconExtDrawable for chaining. */ public IconicsDrawable icon(Character icon) { return iconText(icon.toString()); }
From source file:nodomain.freeyourgadget.gadgetbridge.service.devices.hplus.HPlusSupport.java
/** * HPlus devices accept a subset of GB2312 with some modifications. * This function will apply a custom transliteration. * While related to the methods implemented in LanguageUtils. These are specific for HPLUS * * @param s The String to transliterate//from w w w .jav a 2s . com * @return An array of bytes ready to be sent to the device */ private byte[] encodeStringToDevice(String s) { List<Byte> outBytes = new ArrayList<Byte>(); for (int i = 0; i < s.length(); i++) { Character c = s.charAt(i); byte[] cs; if (HPlusConstants.transliterateMap.containsKey(c)) { cs = new byte[] { HPlusConstants.transliterateMap.get(c) }; } else { try { cs = c.toString().getBytes("GB2312"); } catch (UnsupportedEncodingException e) { //Fallback. Result string may be strange, but better than nothing cs = c.toString().getBytes(); } } for (int j = 0; j < cs.length; j++) outBytes.add(cs[j]); } return ArrayUtils.toPrimitive(outBytes.toArray(new Byte[outBytes.size()])); }
From source file:com.magnet.android.mms.controller.RequestPrimitiveTest.java
@SmallTest public void testSingleListCharPostParam() throws JSONException { ControllerHandler handler = new ControllerHandler(); String methodName = "postChars"; JMethod method = new JMethod(); JMeta metaInfo = new JMeta("postChars", API_METHOD_POST + methodName, POST); method.setMetaInfo(metaInfo);/* w w w . j a v a 2 s .co m*/ // int method.addParam("param0", PLAIN, List.class, Character.class, "", false); List<Character> values = new ArrayList<Character>(); values.add('m'); values.add('a'); values.add('g'); values.add('n'); values.add('e'); values.add('\u00a0'); String uriString = handler.buildUri(method, new Object[] { values }); String bodyString = handler.buildRequestBodyString(method, new Object[] { values }); String expected = API_METHOD_POST + methodName; logger.log(Level.INFO, "uriString=" + uriString); logger.log(Level.INFO, "bodyString=" + bodyString); assertEquals(expected, uriString); JSONArray jarray = new JSONArray(bodyString); int idx = 0; for (Character value : values) { assertEquals(jarray.getString(idx), value.toString()); idx++; } }
From source file:net.sf.jabref.importer.HTMLConverter.java
public String formatUnicode(String text) { if (text == null) { return null; }// w w w . ja v a 2s . c o m Set<Character> chars = unicodeSymbols.keySet(); for (Character character : chars) { // System.err.println(new Integer((int) character).toString() + ": " + character.toString() + ": " + unicodeSymbols.get(character)); text = text.replaceAll(character.toString(), unicodeSymbols.get(character)); } Integer cp; for (int i = 0; i <= (text.length() - 1); i++) { cp = text.codePointAt(i); if (cp >= 129) { LOGGER.warn("Unicode character not converted: " + cp); } } return text; }
From source file:com.clockworks.bigture.identity.impl.UserService.java
@Override public ExpertListWrapper findExpertByName() { List<User> experts = dao.findExperts(); Map<Character, List<ExpertDelegate>> nameMap = new HashMap<Character, List<ExpertDelegate>>(); for (User user : experts) { String name = user.getNickName(); Character firstCh = CommonUtils.getFirstElement(name); List<ExpertDelegate> users = null; if (nameMap.containsKey(firstCh)) { users = nameMap.get(firstCh); } else {/*from w w w . ja va2s. co m*/ users = new ArrayList<ExpertDelegate>(); nameMap.put(firstCh, users); } ExpertDelegate delegate = new ExpertDelegate(user); users.add(delegate); } ExpertListWrapper wrapper = new ExpertListWrapper(); List<Character> keyArray = new ArrayList<Character>(nameMap.keySet()); Collections.sort(keyArray); for (Character ch : keyArray) { WordWrapper word = new WordWrapper(); word.setInitialWord(ch.toString()); word.setExperts(nameMap.get(ch)); wrapper.addWord(word); } return wrapper; }
From source file:org.apache.spark.streaming.JavaAPISuite.java
@SuppressWarnings("unchecked") @Test// www . ja va 2 s . com public void testPairToPairFlatMapWithChangingTypes() { // Maps pair -> pair List<List<Tuple2<String, Integer>>> inputData = Arrays.asList( Arrays.asList(new Tuple2<String, Integer>("hi", 1), new Tuple2<String, Integer>("ho", 2)), Arrays.asList(new Tuple2<String, Integer>("hi", 1), new Tuple2<String, Integer>("ho", 2))); List<List<Tuple2<Integer, String>>> expected = Arrays.asList( Arrays.asList(new Tuple2<Integer, String>(1, "h"), new Tuple2<Integer, String>(1, "i"), new Tuple2<Integer, String>(2, "h"), new Tuple2<Integer, String>(2, "o")), Arrays.asList(new Tuple2<Integer, String>(1, "h"), new Tuple2<Integer, String>(1, "i"), new Tuple2<Integer, String>(2, "h"), new Tuple2<Integer, String>(2, "o"))); JavaDStream<Tuple2<String, Integer>> stream = JavaTestUtils.attachTestInputStream(ssc, inputData, 1); JavaPairDStream<String, Integer> pairStream = JavaPairDStream.fromJavaDStream(stream); JavaPairDStream<Integer, String> flatMapped = pairStream .flatMapToPair(new PairFlatMapFunction<Tuple2<String, Integer>, Integer, String>() { @Override public Iterable<Tuple2<Integer, String>> call(Tuple2<String, Integer> in) throws Exception { List<Tuple2<Integer, String>> out = new LinkedList<Tuple2<Integer, String>>(); for (Character s : in._1().toCharArray()) { out.add(new Tuple2<Integer, String>(in._2(), s.toString())); } return out; } }); JavaTestUtils.attachTestOutputStream(flatMapped); List<List<Tuple2<Integer, String>>> result = JavaTestUtils.runStreams(ssc, 2, 2); Assert.assertEquals(expected, result); }
From source file:org.jboss.bqt.client.xml.XMLQueryVisitationStrategy.java
/** * Produce an XML message for an instance of the Character. * <br>//from w ww.ja v a 2 s .co m * @param object the instance for which the message is to be produced. * @param parent the XML element that is to be the parent of the produced XML message. * @return the root element of the XML segment that was produced. * @exception JDOMException if there is an error producing the message. */ private Element produceMsg(Character object, Element parent) throws JDOMException { // ---------------------- // Create the Character element ... // ---------------------- Element charElement = new Element(TagNames.Elements.CHAR); String v = object.toString(); if (v != null && v.length() != 0) { String toReplace = new String(new Character((char) 0x0).toString()); v.replaceAll(toReplace, " "); charElement.setText(v.trim()); } if (parent != null) { charElement = parent.addContent(charElement); } return charElement; }
From source file:ch.iterate.openstack.swift.Client.java
/** * List all of the objects in a container with the given starting string. * * @param container The container name// w w w .ja v a 2s . c om * @param startsWith The string to start with * @param path Only look for objects in this path * @param limit Return at most <code>limit</code> objects * @param marker Returns objects lexicographically greater than <code>marker</code>. Used in conjunction with <code>limit</code> to paginate the list. * @param delimiter Use this argument as the delimiter that separates "directories" * @return A list of FilesObjects starting with the given string * @throws ch.iterate.openstack.swift.exception.GenericException * Unexpected response * @throws AuthorizationException The openstack's login was invalid. */ public List<StorageObject> listObjectsStartingWith(Region region, String container, String startsWith, String path, int limit, String marker, Character delimiter) throws IOException { LinkedList<NameValuePair> parameters = new LinkedList<NameValuePair>(); parameters.add(new BasicNameValuePair("format", "xml")); if (startsWith != null) { parameters.add(new BasicNameValuePair("prefix", startsWith)); } if (path != null) { parameters.add(new BasicNameValuePair("path", path)); } if (limit > 0) { parameters.add(new BasicNameValuePair("limit", String.valueOf(limit))); } if (marker != null) { parameters.add(new BasicNameValuePair("marker", marker)); } if (delimiter != null) { parameters.add(new BasicNameValuePair("delimiter", delimiter.toString())); } HttpGet method = new HttpGet(region.getStorageUrl(container, parameters)); return this.execute(method, new ObjectResponseHandler()); }