List of usage examples for org.apache.commons.io Charsets ISO_8859_1
Charset ISO_8859_1
To view the source code for org.apache.commons.io Charsets ISO_8859_1.
Click Source Link
From source file:org.jahia.services.templates.ModuleBuildHelper.java
private boolean saveFile(InputStream source, File target) throws IOException { Charset transCodeTarget = null; if (target.getParentFile().getName().equals("resources") && target.getName().endsWith(".properties")) { transCodeTarget = Charsets.ISO_8859_1; }/* ww w. j av a2 s . c o m*/ if (!target.exists()) { if (!target.getParentFile().exists() && !target.getParentFile().mkdirs()) { throw new IOException("Unable to create path for: " + target.getParentFile()); } if (target.getParentFile().isFile()) { target.getParentFile().delete(); target.getParentFile().mkdirs(); } if (transCodeTarget != null) { FileUtils.writeLines(target, transCodeTarget.name(), convertToNativeEncoding(IOUtils.readLines(source, Charsets.UTF_8), transCodeTarget), "\n"); } else { FileOutputStream output = FileUtils.openOutputStream(target); try { IOUtils.copy(source, output); output.close(); } finally { IOUtils.closeQuietly(output); } } // Save repository.xml file after first generation if (target.getName().equals("repository.xml")) { FileUtils.copyFile(target, new File(target.getPath() + ".generated")); } return true; } else { List<String> targetContent = FileUtils.readLines(target, transCodeTarget != null ? transCodeTarget : Charsets.UTF_8); if (!isBinary(targetContent)) { File previouslyGenerated = new File(target.getPath() + ".generated"); List<String> previouslyGeneratedContent = targetContent; if (previouslyGenerated.exists()) { previouslyGeneratedContent = FileUtils.readLines(previouslyGenerated, transCodeTarget != null ? transCodeTarget : Charsets.UTF_8); } DiffMatchPatch dmp = new DiffMatchPatch(); List<String> sourceContent = IOUtils.readLines(source, Charsets.UTF_8); if (transCodeTarget != null) { sourceContent = convertToNativeEncoding(sourceContent, transCodeTarget); } LinkedList<DiffMatchPatch.Patch> l = dmp.patch_make( StringUtils.join(previouslyGeneratedContent, "\n"), StringUtils.join(sourceContent, "\n")); if (target.getName().equals("repository.xml")) { // Keep generated file uptodate FileUtils.writeLines(new File(target.getPath() + ".generated"), transCodeTarget != null ? transCodeTarget.name() : "UTF-8", sourceContent); } if (!l.isEmpty()) { Object[] objects = dmp.patch_apply(l, StringUtils.join(targetContent, "\n")); for (boolean b : ((boolean[]) objects[1])) { if (!b) { throw new IOException("Cannot apply modification on " + target.getName() + ", check generated file at : " + target.getPath() + ".generated"); } } FileUtils.write(target, (CharSequence) objects[0], transCodeTarget != null ? transCodeTarget.name() : "UTF-8"); return true; } } else { byte[] sourceArray = IOUtils.toByteArray(source); FileInputStream input = new FileInputStream(target); FileOutputStream output = null; try { byte[] targetArray = IOUtils.toByteArray(input); if (!Arrays.equals(sourceArray, targetArray)) { output = new FileOutputStream(target); IOUtils.write(sourceArray, output); return true; } } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } } } return false; }
From source file:org.pingaj.app.util.Servlets.java
/** * ??Header.// w w w . j a va 2s .c o m * * @param fileName ???. */ public static void setFileDownloadHeader(HttpServletResponse response, String fileName) { // ??? String encodedfileName = new String(fileName.getBytes(), Charsets.ISO_8859_1); response.setHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + encodedfileName + "\""); }