List of usage examples for java.nio.charset StandardCharsets ISO_8859_1
Charset ISO_8859_1
To view the source code for java.nio.charset StandardCharsets ISO_8859_1.
Click Source Link
From source file:org.h819.commons.file.MyFileUtils.java
/** * Attempts to figure out the character set of the file using the excellent juniversalchardet library. * https://code.google.com/p/juniversalchardet/ * that is the encoding detector library of Mozilla * * @param file// w w w.j ava 2 s .c o m * @return * @throws IOException */ public static Charset getEncoding(File file) throws IOException { byte[] buf = new byte[4096]; BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file)); final UniversalDetector universalDetector = new UniversalDetector(null); int numberOfBytesRead; while ((numberOfBytesRead = bufferedInputStream.read(buf)) > 0 && !universalDetector.isDone()) { universalDetector.handleData(buf, 0, numberOfBytesRead); } universalDetector.dataEnd(); String encoding = universalDetector.getDetectedCharset(); universalDetector.reset(); bufferedInputStream.close(); if (encoding != null) { //??? ISO_8859_1 logger.debug("Detected encoding for {} is {}.", file.getAbsolutePath(), encoding); try { return Charset.forName(encoding); } catch (IllegalCharsetNameException err) { logger.debug("Invalid detected charset name '" + encoding + "': " + err); return StandardCharsets.ISO_8859_1; } catch (UnsupportedCharsetException err) { logger.error("Detected charset '" + encoding + "' not supported: " + err); return StandardCharsets.ISO_8859_1; } } else { logger.info("encodeing is null, will use 'ISO_8859_1' : " + file.getAbsolutePath() + " , " + encoding); return StandardCharsets.ISO_8859_1; } }
From source file:org.sonar.scanner.report.SourcePublisherTest.java
@Before public void prepare() throws IOException { File baseDir = temp.newFolder(); sourceFile = new File(baseDir, "src/Foo.php"); String moduleKey = "foo"; inputFile = new TestInputFileBuilder(moduleKey, "src/Foo.php").setLines(5) .setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1).build(); InputComponentStore componentStore = new InputComponentStore(new PathResolver()); componentStore.put(TestInputFileBuilder.newDefaultInputModule(moduleKey, baseDir)); componentStore.put(inputFile);/*from ww w. ja v a 2 s . co m*/ publisher = new SourcePublisher(componentStore); File outputDir = temp.newFolder(); writer = new ScannerReportWriter(outputDir); }
From source file:com.mirth.connect.plugins.httpauth.basic.BasicAuthenticator.java
@Override public AuthenticationResult authenticate(RequestInfo request) { BasicHttpAuthProperties properties = getReplacedProperties(request); List<String> authHeaderList = request.getHeaders().get(HttpHeader.AUTHORIZATION.asString()); if (CollectionUtils.isNotEmpty(authHeaderList)) { String authHeader = StringUtils.trimToEmpty(authHeaderList.iterator().next()); int index = authHeader.indexOf(' '); if (index > 0) { String method = authHeader.substring(0, index); if (StringUtils.equalsIgnoreCase(method, "Basic")) { // Get Base64-encoded credentials String credentials = StringUtils.trim(authHeader.substring(index)); // Get the raw, colon-separated credentials credentials = new String(Base64.decodeBase64(credentials), StandardCharsets.ISO_8859_1); // Split on ':' to get the username and password index = credentials.indexOf(':'); if (index > 0) { String username = credentials.substring(0, index); String password = credentials.substring(index + 1); // Return successful result if the passwords match if (StringUtils.equals(password, properties.getCredentials().get(username))) { return AuthenticationResult.Success(username, properties.getRealm()); }//from w w w .ja va 2 s. com } } } } // Return authentication challenge return AuthenticationResult.Challenged("Basic realm=\"" + properties.getRealm() + "\""); }
From source file:sh.isaac.converters.sharedUtils.umlsUtils.AbbreviationExpansion.java
/** * Load.//from w ww .jav a2 s. c om * * @param is the is * @return the hash map * @throws IOException Signals that an I/O exception has occurred. */ public static HashMap<String, AbbreviationExpansion> load(InputStream is) throws IOException { final HashMap<String, AbbreviationExpansion> results = new HashMap<>(); final BufferedReader br = new BufferedReader(new InputStreamReader(is, StandardCharsets.ISO_8859_1)); String line = br.readLine(); while (line != null) { if (StringUtils.isBlank(line) || line.startsWith("#")) { line = br.readLine(); continue; } final String[] cols = line.split("\t"); final AbbreviationExpansion ae = new AbbreviationExpansion(cols[0], cols[1], ((cols.length > 2) ? cols[2] : null)); results.put(ae.getAbbreviation(), ae); line = br.readLine(); } return results; }
From source file:org.zanata.adapter.PropertiesLatinOneAdapterTest.java
@Test public void parseLatinOneProperties() throws Exception { File latin1EncodedFile = createTempPropertiesFile(StandardCharsets.ISO_8859_1); Resource resource = adapter.parseDocumentFile(latin1EncodedFile.toURI(), LocaleId.EN, Optional.absent()); assertThat(resource.getTextFlows().get(0).getId()).isEqualTo("line1"); assertThat(resource.getTextFlows().get(0).getContents()).containsExactly("Line One"); }
From source file:com.seleritycorp.common.base.http.client.HttpResponseTest.java
@Test public void testGetBodyIso8859_1() throws Exception { byte[] iso8859_1 = new byte[] { (byte) 0xe4, (byte) 0xfc, (byte) 0xdf, 0x21 }; HttpResponse response = createHttpResponse(200, iso8859_1, StandardCharsets.ISO_8859_1); String actual = response.getBody(); assertThat(actual).isEqualTo("!"); }
From source file:org.eclipse.rcptt.internal.testrail.APIClient.java
public String sendPostRequest(String endpoint, String params) { HttpPost request = new HttpPost(url + endpoint); // Full Unicode support was added in TestRail 2.0, // so we use ISO-8859-1 by default, // but if Unicode is needed, it could be enabled in preferences if (useUnicode) { request.setEntity(new StringEntity(params, StandardCharsets.UTF_8)); } else {/*from w w w.j a v a 2 s . c om*/ request.setEntity(new StringEntity(params, StandardCharsets.ISO_8859_1)); } TestRailPlugin.logInfo(MessageFormat.format(Messages.APIClient_GeneratedRequest, params)); return sendRequest(request); }
From source file:com.bekwam.resignator.util.CryptUtils.java
public String decrypt(String encrypted, String passPhrase) throws IOException, PGPException, NoSuchProviderException { if (StringUtils.isBlank(encrypted)) { throw new IllegalArgumentException("encrypted text is blank"); }/*w w w . j av a 2 s . c om*/ if (StringUtils.isBlank(passPhrase)) { throw new IllegalArgumentException("passPhrase is required"); } byte[] ciphertext; try { ciphertext = Base64.getDecoder().decode(encrypted.getBytes(StandardCharsets.ISO_8859_1)); } catch (IllegalArgumentException exc) { if (logger.isWarnEnabled()) { if (logger.isWarnEnabled()) { logger.warn( "Field could not be decoded. (Config file modified outside of app?) Returning input bytes as encrypted bytes."); } } return encrypted; } byte[] cleartext = decrypt(ciphertext, passPhrase.toCharArray()); return new String(cleartext, StandardCharsets.ISO_8859_1); }
From source file:org.sonar.batch.report.SourcePublisherTest.java
@Before public void prepare() throws IOException { Project p = new Project("foo").setAnalysisDate(new Date(1234567L)); BatchComponentCache resourceCache = new BatchComponentCache(); sampleFile = org.sonar.api.resources.File.create("src/Foo.php"); sampleFile.setEffectiveKey("foo:src/Foo.php"); resourceCache.add(p, null).setInputComponent(new DefaultInputModule("foo")); File baseDir = temp.newFolder(); sourceFile = new File(baseDir, "src/Foo.php"); resourceCache.add(sampleFile, null).setInputComponent(new DefaultInputFile("foo", "src/Foo.php").setLines(5) .setModuleBaseDir(baseDir.toPath()).setCharset(StandardCharsets.ISO_8859_1)); publisher = new SourcePublisher(resourceCache); File outputDir = temp.newFolder(); writer = new BatchReportWriter(outputDir); }
From source file:org.sonar.scanner.report.SourcePublisherTest.java
@Test public void publishEmptySource() throws Exception { FileUtils.write(sourceFile, "", StandardCharsets.ISO_8859_1); publisher.publish(writer);//from ww w . j a v a 2 s . c o m File out = writer.getSourceFile(inputFile.batchId()); assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo(""); }