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:com.thoughtworks.go.websocket.MessageEncoding.java
public static Work decodeWork(String data) { try {/* ww w. ja v a2s . c o m*/ byte[] binary = Base64.getDecoder().decode(data.getBytes(StandardCharsets.UTF_8)); try (ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(binary))) { return (Work) objectStream.readObject(); } } catch (ClassNotFoundException | IOException e) { throw bomb(e); } }
From source file:io.undertow.servlet.test.compat.rewrite.RewriteTestCase.java
@BeforeClass public static void setup() throws ServletException { DeploymentUtils.setupServlet(new ServletExtension() { @Override/*www . j av a2s . co m*/ public void handleDeployment(DeploymentInfo deploymentInfo, ServletContext servletContext) { deploymentInfo.addOuterHandlerChainWrapper(new HandlerWrapper() { @Override public HttpHandler wrap(HttpHandler handler) { byte[] data = "RewriteRule /foo1 /bar1".getBytes(StandardCharsets.UTF_8); RewriteConfig config = RewriteConfigFactory.build(new ByteArrayInputStream(data)); return new RewriteHandler(config, handler); } }); } }, new ServletInfo("servlet", PathTestServlet.class).addMapping("/")); }
From source file:de.elomagic.mag.WebDAVTest.java
@Before public void before() throws Exception { try (InputStream in = getClass().getResourceAsStream("/configuration.properties"); Reader reader = new InputStreamReader(in, StandardCharsets.UTF_8)) { Configuration.loadConfiguration(reader); }/*from ww w . jav a 2 s .com*/ Configuration.set(Configuration.ConfigurationKey.TargetWebDAVEnabled, true); startEMailServer(); startHttpServer(); main = new MAG(); }
From source file:com.toptal.conf.SecurityUtils.java
/** * Encodes given string into base64.//from w w w. j a va2 s.c om * @param str String. * @return Encoded string. */ public static String encode(final String str) { String result = null; if (str != null) { result = Base64.getEncoder().encodeToString(str.getBytes(StandardCharsets.UTF_8)); } return result; }
From source file:ddf.catalog.transformer.csv.common.CsvTransformer.java
public static BinaryContent createResponse(final Appendable csv) { InputStream inputStream = new ByteArrayInputStream(csv.toString().getBytes(StandardCharsets.UTF_8)); return new BinaryContentImpl(inputStream, CSV_MIME_TYPE); }
From source file:jgnash.convert.exportantur.csv.CsvExport.java
public static void exportAccount(final Account account, final LocalDate startDate, final LocalDate endDate, final File file) { Objects.requireNonNull(account); Objects.requireNonNull(startDate); Objects.requireNonNull(endDate); Objects.requireNonNull(file); // force a correct file extension final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".csv"; final CSVFormat csvFormat = CSVFormat.EXCEL.withQuoteMode(QuoteMode.ALL); try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter( Files.newOutputStream(Paths.get(fileName)), StandardCharsets.UTF_8); final CSVPrinter writer = new CSVPrinter(new BufferedWriter(outputStreamWriter), csvFormat)) { outputStreamWriter.write('\ufeff'); // write UTF-8 byte order mark to the file for easier imports writer.printRecord("Account", "Number", "Debit", "Credit", "Balance", "Date", "Timestamp", "Memo", "Payee", "Reconciled"); // write the transactions final List<Transaction> transactions = account.getTransactions(startDate, endDate); final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendValue(MONTH_OF_YEAR, 2).appendValue(DAY_OF_MONTH, 2).toFormatter(); final DateTimeFormatter timestampFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).appendLiteral('-') .appendValue(DAY_OF_MONTH, 2).appendLiteral(' ').appendValue(HOUR_OF_DAY, 2).appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2) .toFormatter();/*from w w w . j av a 2s . c o m*/ for (final Transaction transaction : transactions) { final String date = dateTimeFormatter.format(transaction.getLocalDate()); final String timeStamp = timestampFormatter.format(transaction.getTimestamp()); final String credit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) < 0 ? "" : transaction.getAmount(account).abs().toPlainString(); final String debit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) > 0 ? "" : transaction.getAmount(account).abs().toPlainString(); final String balance = account.getBalanceAt(transaction).toPlainString(); final String reconciled = transaction.getReconciled(account) == ReconciledState.NOT_RECONCILED ? Boolean.FALSE.toString() : Boolean.TRUE.toString(); writer.printRecord(account.getName(), transaction.getNumber(), debit, credit, balance, date, timeStamp, transaction.getMemo(), transaction.getPayee(), reconciled); } } catch (final IOException e) { Logger.getLogger(CsvExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e); } }
From source file:io.servicecomb.common.rest.codec.produce.ProduceTextPlainProcessor.java
@Override public Object doDecodeResponse(InputStream input, JavaType type) throws Exception { // plainTextstring? return IOUtils.toString(input, StandardCharsets.UTF_8); // TODO: //from w ww . ja va2s . c o m // Class<?> returnCls = type.getRawClass(); // if (returnCls.isPrimitive()) { // // ?char // if (returnCls == char.class) { // return ((String)result).charAt(0); // } // // ?int, long, boolean // return RestObjectMapper.INSTANCE.readValue((String)result, type); // } // else { // // ?String?? // // ????"application/json" // return returnCls.getConstructor(new Class<?>[] {String.class}) // .newInstance((String)result); // } }
From source file:com.floragunn.searchguard.test.helper.file.FileHelper.java
public static final String loadFile(final String file) throws IOException { final StringWriter sw = new StringWriter(); IOUtils.copy(FileHelper.class.getResourceAsStream("/" + file), sw, StandardCharsets.UTF_8); return sw.toString(); }
From source file:org.mascherl.example.service.LoginService.java
public static String sha256(String value) { MessageDigest messageDigest = createMessageDigest(); messageDigest.update(value.getBytes(StandardCharsets.UTF_8)); byte[] digest = messageDigest.digest(); byte[] base64Digest = Base64.getEncoder().encode(digest); return new String(base64Digest, StandardCharsets.UTF_8); }
From source file:org.bonitasoft.web.designer.model.JacksonObjectMapperTest.java
@Test public void should_deserialize_json() throws Exception { String json = "{\"name\": \"colin\", \"number\": 31}"; SimpleObject object = objectMapper.fromJson(json.getBytes(StandardCharsets.UTF_8), SimpleObject.class); assertThat(object.getName()).isEqualTo("colin"); assertThat(object.getNumber()).isEqualTo(31); }