List of usage examples for java.nio.charset Charset defaultCharset
Charset defaultCharset
To view the source code for java.nio.charset Charset defaultCharset.
Click Source Link
From source file:org.jmxtrans.embedded.samples.graphite.GraphiteDataInjector.java
public static GraphiteDataInjector newHostedGraphiteDataInjector() { GraphiteDataInjector graphiteDataInjector = new GraphiteDataInjector(); // TODO DEFINE YOUR_HOSTED_GRAPHITE_KEY String hostedGraphiteKey = null; try {//from ww w.j a v a 2 s. c o m hostedGraphiteKey = Resources.toString(Resources.getResource("hosted-graphite.credentials"), Charset.defaultCharset()); } catch (IOException e) { throw Throwables.propagate(e); } graphiteDataInjector.graphiteMetricPrefix = hostedGraphiteKey + ".edu.servers."; graphiteDataInjector.graphiteHost = "carbon.hostedgraphite.com"; graphiteDataInjector.setMaxGraphiteDataPointsPerSecond(100); graphiteDataInjector.batchSize = 50; return graphiteDataInjector; }
From source file:com.shmsoft.dmass.services.Util.java
public static void appendToTextFile(String fileName, String content) throws IOException { Files.append(content, new File(fileName), Charset.defaultCharset()); }
From source file:com.gmail.tylerfilla.axon.ui.activity.HelpFOSSViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate and set content view setContentView(R.layout.activity_help_foss_viewer); // Find stuff Toolbar appBar = (Toolbar) findViewById(R.id.activity_help_foss_viewer_app_bar); WebView browser = (WebView) findViewById(R.id.activity_help_foss_viewer_browser); // Configure app bar setSupportActionBar(appBar);// ww w . ja v a2 s . c o m // Display up button in app bar getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Apply dark tint to navigation icon // noinspection ConstantConditions Drawable navigationIcon = DrawableCompat.wrap(appBar.getNavigationIcon()); DrawableCompat.setTint(navigationIcon, 0x8b000000); appBar.setNavigationIcon(navigationIcon); // Get component index which was passed in int componentIndex = getIntent().getIntExtra("componentIndex", -1); if (componentIndex != -1) { // Component information String componentName = ""; String licenseName = ""; String licenseTextURL = ""; try { // Read components file into a buffer StringWriter componentFileBuffer = new StringWriter(); IOUtils.copy(getAssets().open("foss/components.json"), componentFileBuffer, Charset.defaultCharset()); // Parse component object from file JSONObject component = ((JSONArray) new JSONTokener(componentFileBuffer.toString()).nextValue()) .getJSONObject(componentIndex); // Extract component information from its JSON object componentName = component.getString("name"); licenseName = component.getString("licenseName"); licenseTextURL = component.getString("licenseTextURL"); } catch (IOException e) { e.printStackTrace(); } catch (JSONException e) { e.printStackTrace(); } // Set title and subtitle setTitle(componentName); appBar.setSubtitle(licenseName); // Load license URL browser.loadUrl(licenseTextURL); } }
From source file:edu.wisc.doit.tcrypt.BouncyCastleFileEncrypterDecrypterTest.java
@Test public void testExistingFileDecryption() throws Exception { final InputStream encTestFileInStream = this.getClass().getResourceAsStream("/testFile.txt.tar"); final ByteArrayOutputStream testFileOutStream = new ByteArrayOutputStream(); fileDecrypter.decrypt(encTestFileInStream, testFileOutStream); final String actual = new String(testFileOutStream.toByteArray(), Charset.defaultCharset()).trim(); final InputStream testFileInStream = this.getClass().getResourceAsStream("/testFile.txt"); final String expected = IOUtils.toString(testFileInStream).trim(); assertEquals(expected, actual);// w w w .j av a 2s.c o m }
From source file:de.catma.document.source.contenthandler.DefaultProtocolHandler.java
private void handle(URI sourceDocURI) throws IOException { final String sourceDocURL = sourceDocURI.toURL().toString(); final String sourceURIPath = sourceDocURI.getPath(); SourceDocumentHandler sourceDocumentHandler = new SourceDocumentHandler(); URLConnection urlConnection = new URL(sourceDocURL).openConnection(); InputStream is = urlConnection.getInputStream(); try {//from w w w .jav a 2 s. c o m this.byteContent = IOUtils.toByteArray(is); if (this.mimeType == null) { this.mimeType = sourceDocumentHandler.getMimeType(sourceURIPath, urlConnection, FileType.TEXT.getMimeType()); } this.encoding = Charset.defaultCharset().name(); if (this.mimeType.equals(FileType.TEXT.getMimeType()) || (this.mimeType.equals(FileType.HTML.getMimeType()))) { this.encoding = sourceDocumentHandler.getEncoding(urlConnection, byteContent, Charset.defaultCharset().name()); } } finally { is.close(); } }
From source file:com.jayway.restassured.config.DecoderConfig.java
/** * Configure the decoder config to use the default charset as specified by {@link java.nio.charset.Charset#defaultCharset()} for content decoding. *//*from w ww.j av a 2s. c o m*/ public DecoderConfig() { this(Charset.defaultCharset().toString(), DEFAULT_NO_WRAP_FOR_INFLATE_ENCODED_STREAMS, false, DEFAULT_CHARSET_FOR_CONTENT_TYPE, defaultContentEncoders()); }
From source file:com.fns.grivet.service.NamedQueryServiceSelectTest.java
@BeforeEach public void setUp() throws IOException { Resource r = resolver.getResource("classpath:TestType.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); JSONObject payload = new JSONObject(json); classRegistryService.register(payload); }
From source file:io.jare.tk.TkApp.java
/** * Ctor.//from w ww . j a v a 2 s . com * @param base Base * @return Takes * @throws IOException If fails */ private static Take make(final Base base) throws IOException { if (!"UTF-8".equals(Charset.defaultCharset().name())) { throw new IllegalStateException(String.format("default encoding is %s", Charset.defaultCharset())); } return new TkWithHeaders( new TkVersioned(new TkMeasured(new TkGzip( new TkFlash(new TkAppFallback(new TkAppAuth(new TkForward(TkApp.regex(base)))))))), String.format("X-Jare-Revision: %s", TkApp.REV), "Vary: Cookie"); }
From source file:com.boundary.sdk.event.notification.WebhookRouteBuilderTest.java
@Test public void testNotification() throws InterruptedException, IOException { String body = readFile(NOTIFICATION_JSON, Charset.defaultCharset()); out.setExpectedMessageCount(1);//from www . j a va 2s.c om // Get the url from the sprint DSL file by // 1) Getting the context // 2) Getting the registry // 3) Lookup the bean // 4) Call method to get url // 5) Strip out component name, "jetty:" CamelContext context = out.getCamelContext(); Registry registry = context.getRegistry(); WebHookRouteBuilder builder = (WebHookRouteBuilder) registry.lookupByName("webhook-route-builder"); assertNotNull("builder is null", builder); String url = null; url = builder.getFromUri(); url = url.replaceFirst("jetty:", ""); LOG.debug("url {}", url); // Send an HTTP request with the JSON paylod that is sent // from a Boundary Event Notification HttpClient httpclient = new HttpClient(); PostMethod httppost = new PostMethod(url); Header contentHeader = new Header("Content-Type", "application/json"); httppost.setRequestHeader(contentHeader); StringRequestEntity reqEntity = new StringRequestEntity(body, null, null); httppost.setRequestEntity(reqEntity); // Check our reponse status int status = httpclient.executeMethod(httppost); assertEquals("Received wrong response status", 200, status); // Assert the mock end point out.assertIsSatisfied(); // Get List<Exchange> exchanges = out.getExchanges(); LOG.debug("EXCHANGE COUNT: " + exchanges.size()); for (Exchange exchange : exchanges) { Message message = exchange.getIn(); Object o = message.getBody(); LOG.debug("class: " + o.getClass().toString()); Notification notif = message.getBody(Notification.class); validateNotification(notif); } }
From source file:com.marklogic.contentpump.SingleDocumentWriter.java
public SingleDocumentWriter(Path path, Configuration conf) { dir = path;// w ww.ja v a2 s. co m this.conf = conf; encoding = conf.get(OUTPUT_CONTENT_ENCODING, DEFAULT_ENCODING); if (LOG.isDebugEnabled()) { LOG.debug("Default charset: " + Charset.defaultCharset()); } }