List of usage examples for java.nio.charset Charset name
String name
To view the source code for java.nio.charset Charset name.
Click Source Link
From source file:org.h819.commons.file.MyFileUtils.java
/** * ??/* w ww. java 2 s . com*/ * ? * * @param srcFile ?? * @param descDirectory ?? * @param charset ???? StandardCharsets.UTF_8 */ // ??utf-8 ??? asc ? // gb2312 utf-8 ?? // ? "windows "???? public static void convertEncoding(File srcFile, File descDirectory, Charset charset) { // ? String[] extension = { "java", "html", "htm", "php", "ini", "bat", "css", "txt", "js", "jsp", "xml", "sql", "properties" }; if (!descDirectory.exists()) { descDirectory.mkdir(); } if (srcFile.isFile()) { if (FilenameUtils.isExtension(srcFile.getName().toLowerCase(), extension)) { try { String encodingSrc = MyFileUtils.getEncoding(srcFile).name(); // logger.info(encodingSrc); InputStreamReader in = new InputStreamReader(new FileInputStream(srcFile), encodingSrc); File f = new File(descDirectory + File.separator + srcFile.getName()); OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(f), charset.name()); IOUtils.copy(in, out); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); // logger.info(MyFileUtils.getDetectedEncoding(f).name()); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } else if (srcFile.isDirectory()) { File fs[] = srcFile.listFiles(); for (File f : fs) convertEncoding(f, new File(descDirectory + File.separator + srcFile.getName()), charset); } else { logger.info("wrong file type :" + srcFile.getAbsolutePath()); } }
From source file:works.cirno.mocha.MultiPartItemCommon.java
public String getString(Charset charset) { try {//from w w w . ja va 2 s . c o m return item.getString(charset.name()); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } }
From source file:org.sonar.plugins.checkstyle.CheckstyleConfiguration.java
private void defineCharset(Configuration configuration) { Configuration[] modules = configuration.getChildren(); for (Configuration module : modules) { if ("Checker".equals(module.getName()) || "com.puppycrawl.tools.checkstyle.Checker".equals(module.getName())) { if (module instanceof DefaultConfiguration) { Charset charset = getCharset(); LOG.info("Checkstyle charset: " + charset.name()); ((DefaultConfiguration) module).addAttribute("charset", charset.name()); }//from w ww. ja v a 2 s. c om } } }
From source file:com.microsoft.tfs.core.clients.versioncontrol.localworkspace.IgnoreFile.java
public static IgnoreFile load(final String directory) { Check.notNull(directory, "directory"); //$NON-NLS-1$ IgnoreFile toReturn = null;/*from w w w . ja v a 2 s . c o m*/ try { final String fileName = new File(directory, LocalItemExclusionEvaluator.IGNORE_FILE_NAME) .getAbsolutePath(); if (new File(fileName).exists()) { toReturn = new IgnoreFile(directory); // Discover the current encoding of the file and use that to // write // out the data final FileEncoding tfsEncoding = FileEncodingDetector.detectEncoding(fileName, FileEncoding.AUTOMATICALLY_DETECT); Charset charset = CodePageMapping.getCharset(tfsEncoding.getCodePage(), false); if (charset == null) { /* * getCharset() couldn't find a Java Charset for the code * page. This can happen if the file was detected as * FileEncoding.BINARY. */ charset = CodePageMapping.getCharset(FileEncoding.getDefaultTextEncoding().getCodePage()); } FileInputStream fileStream = null; BufferedReader streamReader = null; try { fileStream = new FileInputStream(fileName); streamReader = new BufferedReader(new InputStreamReader(fileStream, charset.name())); String line; while (null != (line = streamReader.readLine())) { addExcludeEntry(directory, toReturn, line); } } finally { if (fileStream != null) { IOUtils.closeSafely(fileStream); } if (streamReader != null) { IOUtils.closeSafely(streamReader); } } } } catch (final Exception ex) { log.warn("Error loading ignore file", ex); //$NON-NLS-1$ return null; } return toReturn; }
From source file:de.brendamour.jpasskit.PKBarcode.java
public void setMessageEncoding(final Charset messageEncoding) { if (messageEncoding != null) { this.messageEncoding = messageEncoding.name(); } else {/*from ww w . j a va 2s. co m*/ this.messageEncoding = null; } }
From source file:cn.cuizuoli.appranking.http.converter.JsoupHttpMessageConverter.java
@Override protected Document readInternal(Class<? extends Document> clazz, HttpInputMessage inputMessage) throws IOException { Charset charset = getContentTypeCharset(inputMessage.getHeaders().getContentType()); return Jsoup.parse(inputMessage.getBody(), charset.name(), StringUtils.EMPTY); }
From source file:com.nextbook.config.ConfigurableStringHttpMessageConverter.java
@Override protected Long getContentLength(String s, MediaType contentType) { Charset charset = getContentTypeCharset(contentType); try {//from ww w. java 2 s .co m return (long) s.getBytes(charset.name()).length; } catch (UnsupportedEncodingException ex) { // should not occur throw new InternalError(ex.getMessage()); } }
From source file:org.sonar.plugins.scmactivity.BlameVersionSelector.java
public MeasureUpdate detect(InputFile inputFile, String previousSha1, SensorContext context) { File file = inputFile.getFile(); try {//from www. j av a 2s. com Resource resource = fileToResource.toResource(inputFile, context); Charset charset = projectFileSystem.getSourceCharset(); String fileContent = FileUtils.readFileToString(file, charset.name()); String currentSha1 = sha1Generator.find(fileContent); if (currentSha1.equals(previousSha1)) { return fileNotChanged(file, resource); } String[] lines = fileContent.split("(\r)?\n|\r", -1); return fileChanged(file, resource, currentSha1, lines.length); } catch (IOException e) { LOG.error("Unable to get scm information: {}", file, e); return MeasureUpdate.NONE; } }
From source file:org.executequery.gui.prefs.PropertiesGeneral.java
private String[] availableCharsets() { List<String> available = new ArrayList<String>(); SortedMap<String, Charset> charsets = Charset.availableCharsets(); for (Charset charset : charsets.values()) { available.add(charset.name()); }/*from w w w . j ava 2 s .com*/ return available.toArray(new String[available.size()]); }
From source file:com.facetime.cloud.server.support.UTF8HttpMessageConverter.java
@Override protected Long getContentLength(String s, MediaType contentType) { if (contentType != null && contentType.getCharSet() != null) { Charset charset = contentType.getCharSet(); try {/* w ww . j a v a2 s . c o m*/ return (long) s.getBytes(charset.name()).length; } catch (UnsupportedEncodingException ex) { // should not occur throw new InternalError(ex.getMessage()); } } else { return null; } }