List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:org.nuxeo.runtime.TestInlineURLs.java
@Test public void canRead() throws IOException { try (InputStream stream = inlineURL.openStream()) { String inlinedContent = IOUtils.toString(stream, Charsets.UTF_8); assertThat(inlinedContent, equalTo(info)); }//from w w w. java 2 s. c o m }
From source file:org.nuxeo.scim.server.jaxrs.marshalling.NXJsonUnmarshaller.java
@Override public <R extends BaseResource> R unmarshal(final InputStream inputStream, final ResourceDescriptor resourceDescriptor, final ResourceFactory<R> resourceFactory) throws InvalidResourceException { try {/* w w w . j a v a 2 s.com*/ String json = IOUtils.toString(inputStream, Charsets.UTF_8); final JSONObject jsonObject = makeCaseInsensitive(new JSONObject(new JSONTokener(json))); final NXJsonParser parser = new NXJsonParser(); return parser.doUnmarshal(jsonObject, resourceDescriptor, resourceFactory, null); } catch (JSONException | IOException e) { throw new InvalidResourceException("Error while reading JSON: " + e.getMessage(), e); } }
From source file:org.nuxeo.theme.vocabularies.VocabularyManager.java
public List<VocabularyItem> getItems(String name) { VocabularyType vocabularyType = (VocabularyType) Manager.getTypeRegistry().lookup(TypeFamily.VOCABULARY, name);//w ww .ja v a2 s . c o m if (vocabularyType == null) { return null; } final String path = vocabularyType.getPath(); final String className = vocabularyType.getClassName(); if (path == null && className == null) { log.error("Must specify a class name or a path for vocabulary: " + name); return null; } if (path != null && className != null) { log.error("Cannot specify both a class name and a path for vocabulary: " + name); return null; } if (className != null) { Vocabulary vocabulary = getInstance(className); if (vocabulary == null) { log.error("Vocabulary class not found: " + className); return null; } return vocabulary.getItems(); } if (path != null) { if (!path.endsWith(".csv")) { log.error("Only .csv vocabularies are supported: " + path); return null; } final List<VocabularyItem> items = new ArrayList<>(); try (InputStream is = getClass().getClassLoader().getResourceAsStream(path)) { if (is == null) { log.error("Vocabulary file not found: " + path); return null; } try (CSVParser reader = new CSVParser(new InputStreamReader(is, Charsets.UTF_8), CSVFormat.DEFAULT)) { for (CSVRecord record : reader) { final String value = record.get(0); String label = value; if (record.size() >= 2) { label = record.get(1); } items.add(new VocabularyItem(value, label)); } } } catch (IOException e) { log.error("Could not read vocabulary file: " + path, e); } return items; } return null; }
From source file:org.obm.sync.client.impl.AbstractClientImpl.java
@VisibleForTesting void setPostRequestParameters(Request request, Multimap<String, String> parameters) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); for (Entry<String, String> entry : parameters.entries()) { if (entry.getKey() != null && entry.getValue() != null) { nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); }//from ww w . j a v a 2 s .c o m } request.bodyForm(nameValuePairs, Charsets.UTF_8); }
From source file:org.onosproject.drivers.ciena.waveserverai.netconf.CienaWaveserverAiDeviceDescriptionTest.java
/** * Execute the named NETCONF template against the specified session returning * the {@code /rpc-reply/data} section of the response document as a * {@code Node}./*w ww .jav a 2 s .co m*/ * * @param fileName * NETCONF session * @param baseXPath * name of NETCONF request template to execute * @param returnType * return type * @return XML document node that represents the NETCONF response data * @throws NetconfException * if any IO, XPath, or NETCONF exception occurs */ private static Node mockDoRequest(String fileName, String baseXPath, QName returnType) { try { DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = builderFactory.newDocumentBuilder(); URL resource = Resources.getResource(TemplateManager.class, fileName); String resourceS = Resources.toString(resource, Charsets.UTF_8); Document document = builder.parse(new InputSource(new StringReader(resourceS))); XPath xp = XPathFactory.newInstance().newXPath(); return (Node) xp.evaluate(baseXPath, document, returnType); } catch (Exception e) { // e.printStackTrace(); return null; } }
From source file:org.onosproject.xmpp.core.ctl.handlers.XmlStreamDecoderTest.java
@Test public void testDecodeStreamOpen() throws Exception { XmlStreamDecoder decoder = new XmlStreamDecoder(); ByteBuf buffer = Unpooled.buffer();//from w w w.j a va 2 s. com buffer.writeBytes(streamOpenMsg.getBytes(Charsets.UTF_8)); List<Object> list = Lists.newArrayList(); decoder.decode(new ChannelHandlerContextAdapter(), buffer, list); list.forEach(object -> { assertThat(object, is(instanceOf(XMLEvent.class))); }); assertThat(list.size(), is(2)); assertThat(((XMLEvent) list.get(0)).isStartDocument(), is(true)); ((XMLEvent) list.get(0)).isStartElement(); }
From source file:org.onosproject.xmpp.core.ctl.handlers.XmlStreamDecoderTest.java
@Test public void testDecodeStreamClose() throws Exception { XmlStreamDecoder decoder = new XmlStreamDecoder(); // open stream ByteBuf buffer1 = Unpooled.buffer(); buffer1.writeBytes(streamOpenMsg.getBytes(Charsets.UTF_8)); List<Object> list1 = Lists.newArrayList(); decoder.decode(new ChannelHandlerContextAdapter(), buffer1, list1); // close stream ByteBuf buffer2 = Unpooled.buffer(); buffer2.writeBytes(streamCloseMsg.getBytes(Charsets.UTF_8)); List<Object> list2 = Lists.newArrayList(); decoder.decode(new ChannelHandlerContextAdapter(), buffer2, list2); list2.forEach(object -> {/*from www . j a v a 2 s. co m*/ assertThat(object, is(instanceOf(XMLEvent.class))); }); assertThat(list2.size(), is(1)); assertThat(((XMLEvent) list2.get(0)).isEndElement(), is(true)); }
From source file:org.onosproject.xmpp.core.ctl.handlers.XmlStreamDecoderTest.java
@Test public void testDecodeXmppStanza() throws Exception { XmlStreamDecoder decoder = new XmlStreamDecoder(); ByteBuf buffer = Unpooled.buffer();// w w w.java 2s . co m buffer.writeBytes(subscribeMsg.getBytes(Charsets.UTF_8)); List<Object> list = Lists.newArrayList(); decoder.decode(new ChannelHandlerContextAdapter(), buffer, list); assertThat(list.size(), is(10)); list.forEach(object -> { assertThat(object, is(instanceOf(XMLEvent.class))); }); assertThat(((XMLEvent) list.get(0)).isStartDocument(), is(true)); XMLEvent secondEvent = (XMLEvent) list.get(1); assertThat(secondEvent.isStartElement(), is(true)); StartElement secondEventAsStartElement = (StartElement) secondEvent; assertThat(secondEventAsStartElement.getName().getLocalPart(), is("iq")); assertThat(Lists.newArrayList(secondEventAsStartElement.getAttributes()).size(), is(4)); assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("type")).getValue(), is("set")); assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("from")).getValue(), is("test@xmpp.org")); assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("to")).getValue(), is("xmpp.onosproject.org")); assertThat(secondEventAsStartElement.getAttributeByName(QName.valueOf("id")).getValue(), is("sub1")); XMLEvent fourthEvent = (XMLEvent) list.get(3); assertThat(fourthEvent.isStartElement(), is(true)); StartElement fourthEventAsStartElement = (StartElement) fourthEvent; assertThat(fourthEventAsStartElement.getName().getLocalPart(), is("pubsub")); assertThat(fourthEventAsStartElement.getNamespaceURI(""), is("http://jabber.org/protocol/pubsub")); XMLEvent fifthEvent = (XMLEvent) list.get(5); assertThat(fifthEvent.isStartElement(), is(true)); StartElement fifthEventAsStartElement = (StartElement) fifthEvent; assertThat(fifthEventAsStartElement.getName().getLocalPart(), is("subscribe")); assertThat(fifthEventAsStartElement.getAttributeByName(QName.valueOf("node")).getValue(), is("test")); XMLEvent sixthEvent = (XMLEvent) list.get(6); assertThat(sixthEvent.isEndElement(), is(true)); EndElement sixthEventAsEndElement = (EndElement) sixthEvent; assertThat(sixthEventAsEndElement.getName().getLocalPart(), is("subscribe")); XMLEvent seventhEvent = (XMLEvent) list.get(8); assertThat(seventhEvent.isEndElement(), is(true)); EndElement seventhEventAsEndElement = (EndElement) seventhEvent; assertThat(seventhEventAsEndElement.getName().getLocalPart(), is("pubsub")); XMLEvent eighthEvent = (XMLEvent) list.get(9); assertThat(eighthEvent.isEndElement(), is(true)); EndElement eighthEventAsEndElement = (EndElement) eighthEvent; assertThat(eighthEventAsEndElement.getName().getLocalPart(), is("iq")); }
From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java
public static void assertConfiguredOdkApp(String appName, String odkAppVersionFile, String apkVersion) { File versionFile = new File(getMetadataFolder(appName), odkAppVersionFile); if (!versionFile.exists()) { versionFile.getParentFile().mkdirs(); }//from ww w . ja v a 2 s.c o m FileOutputStream fs = null; OutputStreamWriter w = null; BufferedWriter bw = null; try { fs = new FileOutputStream(versionFile, false); w = new OutputStreamWriter(fs, Charsets.UTF_8); bw = new BufferedWriter(w); bw.write(apkVersion); bw.write("\n"); } catch (IOException e) { e.printStackTrace(); } finally { if (bw != null) { try { bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } } if (w != null) { try { w.close(); } catch (IOException e) { e.printStackTrace(); } } try { fs.close(); } catch (IOException e) { e.printStackTrace(); } } }
From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java
private static boolean isConfiguredOdkApp(String appName, String odkAppVersionFile, String apkVersion) { File versionFile = new File(getMetadataFolder(appName), odkAppVersionFile); if (!versionFile.exists()) { return false; }//from w w w .j a v a 2s. com String versionLine = null; FileInputStream fs = null; InputStreamReader r = null; BufferedReader br = null; try { fs = new FileInputStream(versionFile); r = new InputStreamReader(fs, Charsets.UTF_8); br = new BufferedReader(r); versionLine = br.readLine(); } catch (IOException e) { e.printStackTrace(); return false; } finally { if (br != null) { try { br.close(); } catch (IOException e) { e.printStackTrace(); } } if (r != null) { try { r.close(); } catch (IOException e) { e.printStackTrace(); } } try { fs.close(); } catch (IOException e) { e.printStackTrace(); } } String[] versionRange = versionLine.split(";"); for (String version : versionRange) { if (version.trim().equals(apkVersion)) { return true; } } return false; }