List of usage examples for java.nio.charset StandardCharsets UTF_8
Charset UTF_8
To view the source code for java.nio.charset StandardCharsets UTF_8.
Click Source Link
From source file:at.ac.tuwien.dsg.dataassetloader.store.MySqlDataAssetStore.java
public void storeDataAsset(String daXML, String dafName, String partitionID) { InputStream daStream = new ByteArrayInputStream(daXML.getBytes(StandardCharsets.UTF_8)); MySqlConnectionManager connectionManager = new MySqlConnectionManager(ip, port, db, user, pass); String sql = "INSERT INTO DataAsset(daw_name,partitionID,da) VALUES ('" + dafName + "','" + partitionID + "',?)"; List<InputStream> listOfInputStreams = new ArrayList<InputStream>(); listOfInputStreams.add(daStream);/*w w w. j av a2s .c o m*/ connectionManager.ExecuteUpdateBlob(sql, listOfInputStreams); }
From source file:com.soft160.app.blobstore.HttpMessageHandler.java
private void Get(HttpExchange he) throws IOException, RocksDBException, ClassNotFoundException { List<NameValuePair> pairs = URLEncodedUtils.parse(he.getRequestURI().getQuery(), StandardCharsets.UTF_8); UUID bucket = null, file = null; for (NameValuePair pair : pairs) { if (pair.getName().equalsIgnoreCase("bucket")) { bucket = parseUUID(pair.getValue()); } else if (pair.getName().equalsIgnoreCase("blob")) { file = parseUUID(pair.getValue()); }//ww w. j a va 2 s. com } if (bucket == null || file == null) { SendResponse(he, HttpStatus.SC_BAD_REQUEST, "Unknown bucket/file"); } BlobInfo info = localStore.GetBlob(bucket, file); if (info == null) { SendResponse(he, HttpStatus.SC_NOT_FOUND, "bucket/file not found"); } else { he.getResponseHeaders().add("Content-Type", "application/octet-stream"); he.getResponseHeaders().add("Content-Length", Integer.toString(info.size)); try (FileInputStream inFile = new FileInputStream(info.path)) { he.sendResponseHeaders(HttpStatus.SC_OK, inFile.getChannel().size()); IOUtils.copy(inFile, he.getResponseBody()); } } }
From source file:com.epam.wilma.webapp.stub.response.formatter.string.StringRegexpReplaceTemplateFormatter.java
@Override public byte[] formatTemplate(final WilmaHttpRequest wilmaRequest, final HttpServletResponse resp, final byte[] templateResource, final ParameterList params) throws Exception { byte[] result = templateResource; String template = null;/*from w ww . ja v a 2s .c o m*/ if (!params.getAllParameters().isEmpty()) { template = getTemplate(templateResource, params); result = template.getBytes(StandardCharsets.UTF_8); } return result; }
From source file:org.bonitasoft.web.designer.controller.utils.HttpFile.java
/** * Write headers and content in the response */// w w w . ja v a 2 s. com private static void writeFileInResponse(HttpServletResponse response, Path filePath, String mimeType, String contentDispositionType) throws IOException { response.setHeader("Content-Type", mimeType); response.setHeader("Content-Length", String.valueOf(filePath.toFile().length())); response.setHeader("Content-Disposition", new StringBuilder().append(contentDispositionType) .append("; filename=\"").append(filePath.getFileName()).append("\"").toString()); response.setCharacterEncoding(StandardCharsets.UTF_8.toString()); try (OutputStream out = response.getOutputStream()) { Files.copy(filePath, out); } }
From source file:com.byteatebit.nbserver.simple.TestSimpleNbServer.java
@Test public void testWriteClose() throws IOException { // Create a task to be executed following the acceptance of a new connection to the server socketChannel. // This task is the application entry point. // This task will write out the message "Hello and Goodbye" and then close the connection. ISocketChannelHandler socketChannelHandler = (nbContext, socket) -> WriteMessageTask.Builder.builder() .withByteBuffer(ByteBuffer.allocate(2048)).build() .writeMessage("Hello and Goodbye\n".getBytes(StandardCharsets.UTF_8), nbContext, socket, () -> IOUtils.closeQuietly(socket), (e) -> LOG.error("Write failed", e)); // create the server SimpleNbServer simpleNbServer = SimpleNbServer.Builder.builder() .withConfig(/*from w ww. j av a 2 s.co m*/ SimpleNbServerConfig.builder().withListenAddress("localhost").withListenPort(1111).build()) // Here we configure the provider for the listening socketChannel. In this case, // a TCP server socketChannel will be created using the default TcpAcceptedConnectionHandler // to handle incoming connections and pass them off to the socketChannelHandler .withConnectorFactory(TcpConnectorFactory.Builder.builder() // supply the application entry point .withConnectedSocketTask(socketChannelHandler).build()) .build(); try { simpleNbServer.start(); Socket socket = new Socket("localhost", 1111); BufferedReader reader = new BufferedReader( new InputStreamReader(socket.getInputStream(), StandardCharsets.UTF_8)); String message = reader.readLine(); System.out.println("Received message '" + message + "' from the server"); Assert.assertEquals("Hello and Goodbye", message); socket.close(); } finally { simpleNbServer.shutdown(); } }
From source file:com.dreamerpartner.codereview.lucene.SearchHelper.java
@SuppressWarnings("deprecation") public static Document getById(String module, String id) { if (StringUtils.isEmpty(id)) return null; IndexReader reader = null;/*from www. jav a2 s .c om*/ try { reader = DirectoryReader.open(FSDirectory.open(new File(LuceneUtil.getIndexPath(module)))); IndexSearcher searcher = new IndexSearcher(reader); BufferedReader in = new BufferedReader(new InputStreamReader(System.in, StandardCharsets.UTF_8)); Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_4_10_0); //? QueryParser parser = new QueryParser(Version.LUCENE_4_10_0, "id", analyzer); Query query = parser.parse(id); return searchOne(in, searcher, query); } catch (Exception e) { logger.error(id + " getById fail.", e); } finally { try { if (reader != null) reader.close(); } catch (IOException e) { e.printStackTrace(); } } return null; }
From source file:com.grantingersoll.opengrok.analysis.sh.TestShSymbolTokenizer.java
@Test public void test() throws Exception { String input;/*from w w w . j ava 2 s .c o m*/ try (InputStream stream = TestShSymbolTokenizer.class.getResourceAsStream("bazaar.sh"); Reader in = new InputStreamReader(stream, StandardCharsets.UTF_8)) { input = IOUtils.toString(in); } String[] output = new String[] { //// #! /bin/ksh //// # //// # CDDL HEADER START //// # //// # The contents of this file are subject to the terms of the //// # Common Development and Distribution License (the "License"). //// # You may not use this file except in compliance with the License. //// # //// # See LICENSE.txt included in this distribution for the specific //// # language governing permissions and limitations under the License. //// # //// # When distributing Covered Code, include this CDDL HEADER in each //// # file and include the License file at LICENSE.txt. //// # If applicable, add the following below this CDDL HEADER, with the //// # fields enclosed by brackets "[]" replaced with your own identifying //// # information: Portions Copyright [yyyy] [name of copyright owner] //// # //// # CDDL HEADER END //// # //// # Dummy wrapper-script to set up the PYTHONPATH and start bzr.. "PYTHONPATH", "HOME", "bin", "bazaar", "lib", "python2", "site", "packages", //// PYTHONPATH=${HOME}/bin/bazaar/lib/python2.5/site-packages "LC_ALL", //// LC_ALL="C" "PYTHONPATH", "LC_ALL", //// export PYTHONPATH LC_ALL "HOME", "bin", "bazaar", "bin", "bzr", //// ${HOME}/bin/bazaar/bin/bzr "$@" //// exit $? //// }; assertAnalyzesTo(analyzer, input, output); }
From source file:org.bonitasoft.web.designer.model.JacksonObjectMapper.java
public String prettyPrint(String json) throws IOException { return objectMapper.writerWithDefaultPrettyPrinter() .writeValueAsString(fromJson(json.getBytes(StandardCharsets.UTF_8), Object.class)); }
From source file:car_counter.processing.TestDefaultProcessor.java
@Before public void setUp() throws Exception { BasicConfigurator.configure();//from w w w .j ava 2 s . c o m dbFile = Files.createTempFile("test", ".db"); tempDirectory = Files.createTempDirectory("test"); incoming = tempDirectory.resolve("incoming"); data = tempDirectory.resolve("data"); Files.createDirectories(incoming); Files.createDirectories(data); String iniValue = String.format( "[Counting]\n" + "implementation = noop\n" + "[Storage]\n" + "implementation = sqlite\n" + "database = %s\n" + "[Processing]\n" + "incoming = %s\n" + "data = %s\n", dbFile, incoming, data); ini = new Wini(); ini.getConfig().setMultiOption(true); try (InputStream stream = IOUtils.toInputStream(iniValue, StandardCharsets.UTF_8)) { ini.load(stream); } }
From source file:com.joyent.manta.client.AuthAwareConfigContextTest.java
public void canMonitorRelevantFieldsInConfig() throws IOException { final AuthAwareConfigContext authConfig = new AuthAwareConfigContext(config); final KeyPair currentKeyPair = authConfig.getKeyPair(); Assert.assertNotNull(currentKeyPair); // key file (move key content to a file) final File keyFile = File.createTempFile("private-key", ""); FileUtils.forceDeleteOnExit(keyFile); FileUtils.writeStringToFile(keyFile, authConfig.getPrivateKeyContent(), StandardCharsets.UTF_8); authConfig.setPrivateKeyContent(null); authConfig.setMantaKeyPath(keyFile.getAbsolutePath()); authConfig.reload();/* w w w . jav a 2 s . c o m*/ differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // key id authConfig.setMantaKeyId("MD5:" + KeyFingerprinter.md5Fingerprint(authConfig.getKeyPair())); authConfig.reload(); differentKeyPairsSameContent(currentKeyPair, authConfig.getKeyPair()); // disable native signatures final ThreadLocalSigner currentSigner = authConfig.getSigner(); authConfig.setDisableNativeSignatures(true); authConfig.reload(); Assert.assertNotSame(currentSigner, authConfig.getSigner()); // disable auth entirely authConfig.setNoAuth(true); authConfig.reload(); Assert.assertNull(authConfig.getKeyPair()); }