Example usage for org.apache.commons.io Charsets UTF_8

List of usage examples for org.apache.commons.io Charsets UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for org.apache.commons.io Charsets UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

private void checkCndFormat(ExternalData data) throws RepositoryException {
    if (data.getProperties().get(SOURCE_CODE) != null) {
        byte[] sourceCode = data.getProperties().get(SOURCE_CODE)[0].getBytes();
        try {/*from ww  w .  j a  va 2 s  . c o m*/
            Reader resourceReader = null;
            try {
                NodeTypeRegistry ntr = createBaseRegistry();
                resourceReader = new InputStreamReader(new ByteArrayInputStream(sourceCode), Charsets.UTF_8);
                JahiaCndReader r = new JahiaCndReader(resourceReader, data.getName(), module.getId(), ntr);
                r.parse();
            } finally {
                IOUtils.closeQuietly(resourceReader);
            }

        } catch (ParseException | IOException e) {
            throw new RepositoryException(e.getMessage());
        }
    }
}

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

private synchronized boolean saveEditableFile(ExternalData data, ExtendedNodeType type)
        throws RepositoryException {
    boolean hasProperties = false;
    // Handle source code
    OutputStream outputStream = null;
    try {/*from w w w  .  j a v a  2 s.  c o  m*/
        //don't write code if file is empty
        if (data.getProperties().get(SOURCE_CODE) != null) {
            outputStream = getFile(data.getPath()).getContent().getOutputStream();
            byte[] sourceCode = data.getProperties().get(SOURCE_CODE)[0].getBytes(Charsets.UTF_8);
            outputStream.write(sourceCode);
        }
    } catch (Exception e) {
        logger.error("Failed to write source code", e);
        throw new RepositoryException("Failed to write source code", e);
    } finally {
        IOUtils.closeQuietly(outputStream);
    }

    // Handle properties
    if (type.isNodeType(Constants.JAHIAMIX_VIEWPROPERTIES)) {
        hasProperties = true;
        saveProperties(data);
    }

    if (type.isNodeType(JNT_DEFINITION_FILE)) {
        removeNodeTypeRegistry(data.getPath());
    }
    return hasProperties;
}

From source file:org.jahia.modules.external.modules.ModulesDataSource.java

@Override
public String[] getPropertyValues(String path, String propertyName) throws PathNotFoundException {
    if (SOURCE_CODE.equals(propertyName)) {
        InputStream is = null;//w  w w. ja  va  2 s .  c  o  m
        try {
            is = getFile(path).getContent().getInputStream();
            java.nio.charset.Charset c = path.toLowerCase().endsWith(".properties") ? Charsets.ISO_8859_1
                    : Charsets.UTF_8;
            return new String[] { IOUtils.toString(is, c) };
        } catch (Exception e) {
            logger.error("Failed to read source code", e);
        } finally {
            IOUtils.closeQuietly(is);
        }
    }
    throw new PathNotFoundException(path + "/" + propertyName);
}

From source file:org.jahia.services.content.nodetypes.NodeTypeRegistry.java

public void addDefinitionsFile(List<? extends Resource> resources, String systemId)
        throws IOException, ParseException, RepositoryException {
    List<ExtendedNodeType> types = new ArrayList<>();
    for (Resource resource : resources) {
        logger.debug("Adding definitions file {} for {}", resource, systemId);
        Reader resourceReader = null;
        try {//from  www. ja v a  2 s.c  o m
            resourceReader = new InputStreamReader(resource.getInputStream(), Charsets.UTF_8);
            JahiaCndReader r = new JahiaCndReader(resourceReader, resource.toString(), systemId, this);
            r.parse();
            types.addAll(r.getNodeTypesList());
        } finally {
            IOUtils.closeQuietly(resourceReader);
        }
    }

    registerNodeTypes(types);

    if (!files.containsKey(systemId)) {
        files.put(systemId, new ArrayList<Resource>());
    }
    for (Resource resource : resources) {
        if (!files.get(systemId).contains(resource)) {
            files.get(systemId).add(resource);
        }
    }
}

From source file:org.jahia.services.content.nodetypes.NodeTypeRegistry.java

/**
 * Reads the specified CND file resource and parses it to obtain a list of node type definitions.
 * //from   w ww  .j ava2  s  . c  o  m
 * @param resource
 *            a resource, representing a CND file
 * @param systemId
 *            the ID to use to specify the "origin" on the node types from this file
 * @return a list of the node types parsed from the specified resource
 * @throws ParseException
 *             in case of a parsing error
 * @throws IOException
 *             in case of an I/O error when reading the specified resource
 */
public List<ExtendedNodeType> getDefinitionsFromFile(Resource resource, String systemId)
        throws ParseException, IOException {
    String ext = resource.getURL().getPath().substring(resource.getURL().getPath().lastIndexOf('.'));
    if (ext.equalsIgnoreCase(".cnd")) {
        Reader resourceReader = null;
        try {
            resourceReader = new InputStreamReader(resource.getInputStream(), Charsets.UTF_8);
            JahiaCndReader r = new JahiaCndReader(resourceReader, resource.getURL().getPath(), systemId, this);
            r.parse();
            return r.getNodeTypesList();
        } finally {
            IOUtils.closeQuietly(resourceReader);
        }
    }
    return Collections.emptyList();
}

From source file:org.jahia.services.importexport.ImportExportBaseService.java

/**
 * Import a full site zip into a newly created site.
 * <p/>/* w  w w.  j  a va  2  s  .  co m*/
 * zip file can contain all kind of legacy jahia import files or jcr import format.
 *
 * @param file                      Zip file
 * @param site                      The new site where to import
 * @param infos                     site infos
 * @param legacyMappingFilePath     path to the legacy mappings
 * @param legacyDefinitionsFilePath path for the legacy definitions
 * @param session                   the current JCR session to use for the import
 * @throws RepositoryException
 * @throws IOException
 */
public void importSiteZip(Resource file, JahiaSite site, Map<Object, Object> infos,
        Resource legacyMappingFilePath, Resource legacyDefinitionsFilePath, JCRSessionWrapper session)
        throws RepositoryException, IOException {
    long timerSite = System.currentTimeMillis();
    logger.info("Start import for site {}", site != null ? site.getSiteKey() : "");

    final CategoriesImportHandler categoriesImportHandler = new CategoriesImportHandler();
    final UsersImportHandler usersImportHandler = new UsersImportHandler(site, session);

    boolean legacyImport = false;
    List<String[]> catProps = null;
    List<String[]> userProps = null;

    Map<String, Long> sizes = new HashMap<String, Long>();
    List<String> fileList = new ArrayList<String>();

    logger.info("Start analyzing import file {}", file);
    long timer = System.currentTimeMillis();
    getFileList(file, sizes, fileList);
    logger.info("Done analyzing import file {} in {}", file,
            DateUtils.formatDurationWords(System.currentTimeMillis() - timer));

    Map<String, String> pathMapping = session.getPathMapping();
    for (JahiaTemplatesPackage pkg : templatePackageRegistry.getRegisteredModules().values()) {
        String key = "/modules/" + pkg.getId() + "/";
        if (!pathMapping.containsKey(key)) {
            pathMapping.put(key, "/modules/" + pkg.getId() + "/" + pkg.getVersion() + "/");
        }
    }

    ZipInputStream zis;
    if (sizes.containsKey(USERS_XML)) {
        // Import users first
        zis = getZipInputStream(file);
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.equals(USERS_XML)) {
                    userProps = importUsers(zis, usersImportHandler);
                    break;
                }
                zis.closeEntry();
            }
        } finally {
            closeInputStream(zis);
        }
    }

    // Check if it is an 5.x or 6.1 import :
    for (Map.Entry<String, Long> entry : sizes.entrySet()) {
        if (entry.getKey().startsWith("export_")) {
            legacyImport = true;
            break;
        }
    }

    if (sizes.containsKey(SITE_PROPERTIES)) {
        zis = getZipInputStream(file);
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.equals(SITE_PROPERTIES)) {
                    importSiteProperties(zis, site, session);
                    break;
                }
                zis.closeEntry();
            }
        } finally {
            closeInputStream(zis);
        }
    }

    if (sizes.containsKey(REPOSITORY_XML)) {
        // Parse import file to detect sites
        zis = getZipInputStream(file);
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.equals(REPOSITORY_XML)) {
                    timer = System.currentTimeMillis();
                    logger.info("Start importing " + REPOSITORY_XML);

                    DocumentViewValidationHandler h = new DocumentViewValidationHandler();
                    h.setSession(session);
                    List<ImportValidator> validators = new ArrayList<ImportValidator>();
                    SitesValidator sitesValidator = new SitesValidator();
                    validators.add(sitesValidator);
                    h.setValidators(validators);
                    handleImport(zis, h, name);

                    Map<String, Properties> sites = ((SitesValidatorResult) sitesValidator.getResult())
                            .getSitesProperties();
                    for (String s : sites.keySet()) {
                        // Only the first site returned is mapped (if its not the systemsite, which is always the same key)
                        if (!s.equals("systemsite") && !site.getSiteKey().equals("systemsite")) {
                            // Map to the new sitekey
                            pathMapping.put("/sites/" + s + "/", "/sites/" + site.getSiteKey() + "/");
                            break;
                        }
                    }

                    if (!sizes.containsKey(SITE_PROPERTIES)) {
                        // todo : site properties can be removed and properties get from here
                    }
                    logger.info("Done importing " + REPOSITORY_XML + " in {}",
                            DateUtils.formatDurationWords(System.currentTimeMillis() - timer));
                    break;
                }
                zis.closeEntry();
            }
        } finally {
            closeInputStream(zis);
        }

        importZip(null, file, DocumentViewImportHandler.ROOT_BEHAVIOUR_IGNORE, session,
                Sets.newHashSet(USERS_XML, CATEGORIES_XML), true);
    } else {
        // No repository descriptor - prepare to import files directly
        pathMapping.put("/", "/sites/" + site.getSiteKey() + "/files/");
    }

    NodeTypeRegistry reg = NodeTypeRegistry.getInstance();
    DefinitionsMapping mapping = null;

    // Import additional files - site.properties, old cateogries.xml , sitepermissions.xml
    // and eventual plain file from 5.x imports
    if (!sizes.containsKey(REPOSITORY_XML) || sizes.containsKey(SITE_PROPERTIES)
            || sizes.containsKey(CATEGORIES_XML) || sizes.containsKey(SITE_PERMISSIONS_XML)
            || sizes.containsKey(DEFINITIONS_CND) || sizes.containsKey(DEFINITIONS_MAP)) {
        zis = getZipInputStream(file);
        try {
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.indexOf('\\') > -1) {
                    name = name.replace('\\', '/');
                }
                if (name.indexOf('/') > -1) {
                    if (!sizes.containsKey(REPOSITORY_XML) && !sizes.containsKey(FILESACL_XML)) {
                        // No repository descriptor - Old import format only
                        name = "/" + name;
                        if (name.startsWith("/content/sites")) {
                            name = pathMapping.get("/") + StringUtils
                                    .stripStart(name.replaceFirst("/content/sites/[^/]+/files/", ""), "/");
                        } else if (name.startsWith("/users")) {
                            Matcher m = Pattern.compile("/users/([^/]+)(/.*)?").matcher(name);
                            if (m.matches()) {
                                name = ServicesRegistry.getInstance().getJahiaUserManagerService()
                                        .getUserSplittingRule().getPathForUsername(m.group(1));
                                name = name + "/files" + ((m.group(2) != null) ? m.group(2) : "");
                            }
                        } else if (name.startsWith("/content/users")) {
                            Matcher m = Pattern.compile("/content/users/([^/]+)(/.*)?").matcher(name);
                            if (m.matches()) {
                                name = ServicesRegistry.getInstance().getJahiaUserManagerService()
                                        .getUserSplittingRule().getPathForUsername(m.group(1));
                                name = name + ((m.group(2) != null) ? m.group(2) : "");
                            }
                        } else {
                            name = pathMapping.get("/") + StringUtils.stripStart(name, "/");
                        }
                        if (!zipentry.isDirectory()) {
                            try {
                                String filename = name.substring(name.lastIndexOf('/') + 1);
                                ensureFile(session, name, zis, JCRContentUtils.getMimeType(filename), site);
                            } catch (Exception e) {
                                logger.error("Cannot upload file " + zipentry.getName(), e);
                            }
                        } else {
                            ensureDir(session, name, site);
                        }
                    }
                } else if (name.equals(CATEGORIES_XML)) {
                    catProps = importCategoriesAndGetUuidProps(zis, categoriesImportHandler);
                } else if (name.equals(DEFINITIONS_CND)) {
                    reg = new NodeTypeRegistry(); // this is fishy: a new instance is created here when NodeTypeRegistry is meant to be used as a singleton
                    try {
                        for (Map.Entry<String, File> entry : NodeTypeRegistry.getSystemDefinitionsFiles()
                                .entrySet()) {
                            reg.addDefinitionsFile(entry.getValue(), entry.getKey());
                        }
                        if (legacyImport) {
                            JahiaCndReaderLegacy r = new JahiaCndReaderLegacy(
                                    new InputStreamReader(zis, Charsets.UTF_8), zipentry.getName(),
                                    file.getURL().getPath(), reg);
                            r.parse();
                        } else {
                            reg.addDefinitionsFile(new InputStreamResource(zis, zipentry.getName()),
                                    file.getURL().getPath());
                        }
                    } catch (RepositoryException | ParseException e) {
                        logger.error(e.getMessage(), e);
                    }
                } else if (name.equals(DEFINITIONS_MAP)) {
                    mapping = new DefinitionsMapping();
                    mapping.load(zis);

                }
                zis.closeEntry();
            }
        } finally {
            closeInputStream(zis);
        }
    }

    // Import legacy content from 5.x and 6.x
    if (legacyImport) {
        long timerLegacy = System.currentTimeMillis();
        final String originatingJahiaRelease = (String) infos.get("originatingJahiaRelease");
        logger.info("Start legacy import, source version is " + originatingJahiaRelease);
        if (legacyMappingFilePath != null) {
            mapping = new DefinitionsMapping();
            final InputStream fileInputStream = legacyMappingFilePath.getInputStream();
            try {
                mapping.load(fileInputStream);
            } finally {
                IOUtils.closeQuietly(fileInputStream);
            }
        }
        if (legacyDefinitionsFilePath != null) {
            reg = new NodeTypeRegistry();
            if ("6.1".equals(originatingJahiaRelease)) {
                logger.info("Loading the built in 6.1 definitions before processing the provided custom ones");
                final List<String> builtInLegacyDefs = Arrays.asList("01-system-nodetypes.cnd",
                        "02-jahiacore-nodetypes.cnd", "03-files-nodetypes.cnd", "04-jahiacontent-nodetypes.cnd",
                        "05-standard-types.cnd", "10-extension-nodetypes.cnd", "11-preferences-nodetypes.cnd");

                for (String builtInLegacyDefsFile : builtInLegacyDefs) {
                    InputStreamReader inputStreamReader = null;
                    try {
                        final InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(
                                "org/jahia/migration/legacyDefinitions/jahia6/" + builtInLegacyDefsFile);
                        if (inputStream != null) {
                            inputStreamReader = new InputStreamReader(inputStream, "UTF-8");
                            final JahiaCndReaderLegacy r = new JahiaCndReaderLegacy(inputStreamReader,
                                    builtInLegacyDefsFile, file.getURL().getPath(), reg);
                            r.parse();
                        } else {
                            logger.error("Couldn't load " + builtInLegacyDefsFile);
                        }
                    } catch (ParseException e) {
                        logger.error(e.getMessage(), e);
                    } finally {
                        IOUtils.closeQuietly(inputStreamReader);
                    }
                }
            } else {
                try {
                    for (Map.Entry<String, File> entry : NodeTypeRegistry.getSystemDefinitionsFiles()
                            .entrySet()) {
                        reg.addDefinitionsFile(entry.getValue(), entry.getKey());
                    }
                } catch (ParseException e) {
                    logger.error("Cannot parse definitions : " + e.getMessage(), e);
                }
            }
            InputStreamReader streamReader = null;
            try {
                streamReader = new InputStreamReader(legacyDefinitionsFilePath.getInputStream(), "UTF-8");
                JahiaCndReaderLegacy r = new JahiaCndReaderLegacy(streamReader,
                        legacyDefinitionsFilePath.getFilename(), file.getURL().getPath(), reg);
                r.parse();
            } catch (ParseException e) {
                logger.error(e.getMessage(), e);
            } finally {
                IOUtils.closeQuietly(streamReader);
            }
        }
        // Old import
        JCRNodeWrapper siteFolder = session.getNode("/sites/" + site.getSiteKey());

        zis = new NoCloseZipInputStream(new BufferedInputStream(file.getInputStream()));
        try {
            int legacyImportHandlerCtnId = 1;
            while (true) {
                ZipEntry zipentry = zis.getNextEntry();
                if (zipentry == null)
                    break;
                String name = zipentry.getName();
                if (name.equals(FILESACL_XML)) {
                    logger.info("Importing file " + FILESACL_XML);
                    importFilesAcl(site, file, zis, mapping, fileList);
                } else if (name.startsWith("export")) {
                    logger.info("Importing file " + name);
                    String languageCode;
                    if (name.indexOf("_") != -1) {
                        languageCode = name.substring(7, name.lastIndexOf("."));
                    } else {
                        languageCode = site.getLanguagesAsLocales().iterator().next().toString();
                    }
                    zipentry.getSize();

                    LegacyImportHandler importHandler = new LegacyImportHandler(session, siteFolder, reg,
                            mapping, LanguageCodeConverters.languageCodeToLocale(languageCode),
                            infos != null ? originatingJahiaRelease : null, legacyPidMappingTool,
                            legacyImportHandlerCtnId);
                    Map<String, List<String>> references = new LinkedHashMap<String, List<String>>();
                    importHandler.setReferences(references);

                    InputStream documentInput = zis;
                    if (this.xmlContentTransformers != null && this.xmlContentTransformers.size() > 0) {
                        documentInput = new ZipInputStream(file.getInputStream());
                        while (!name.equals(((ZipInputStream) documentInput).getNextEntry().getName()))
                            ;
                        byte[] buffer = new byte[2048];
                        final File tmpDirectoryForSite = new File(
                                new File(System.getProperty("java.io.tmpdir"), "jahia-migration"),
                                FastDateFormat.getInstance("yyyy_MM_dd-HH_mm_ss_SSS").format(timerSite) + "_"
                                        + site.getSiteKey());
                        tmpDirectoryForSite.mkdirs();
                        File document = new File(tmpDirectoryForSite,
                                "export_" + languageCode + "_00_extracted.xml");
                        final OutputStream output = new BufferedOutputStream(new FileOutputStream(document),
                                2048);
                        int count = 0;
                        while ((count = documentInput.read(buffer, 0, 2048)) > 0) {
                            output.write(buffer, 0, count);
                        }
                        output.flush();
                        output.close();
                        documentInput.close();
                        for (XMLContentTransformer xct : xmlContentTransformers) {
                            document = xct.transform(document, tmpDirectoryForSite);
                        }
                        documentInput = new FileInputStream(document);
                    }

                    handleImport(documentInput, importHandler, name);
                    legacyImportHandlerCtnId = importHandler.getCtnId();
                    ReferencesHelper.resolveCrossReferences(session, references);
                    siteFolder.getSession().save(JCRObservationManager.IMPORT);
                }
                zis.closeEntry();
            }
            ReferencesHelper.resolveReferencesKeeper(session);
            siteFolder.getSession().save(JCRObservationManager.IMPORT);
        } finally {
            closeInputStream(zis);
        }
        logger.info("Done legacy import in {}",
                DateUtils.formatDurationWords(System.currentTimeMillis() - timerLegacy));
    }

    categoriesImportHandler.setUuidProps(catProps);
    usersImportHandler.setUuidProps(userProps);

    // session.save();
    session.save(JCRObservationManager.IMPORT);
    cleanFilesList(fileList);

    if (legacyImport && this.postImportPatcher != null) {
        final long timerPIP = System.currentTimeMillis();
        logger.info("Executing post import patches");
        this.postImportPatcher.executePatches(site);
        logger.info("Executed post import patches in {}",
                DateUtils.formatDurationWords(System.currentTimeMillis() - timerPIP));
    }

    logger.info("Done importing site {} in {}", site != null ? site.getSiteKey() : "",
            DateUtils.formatDurationWords(System.currentTimeMillis() - timerSite));
}

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;
    }/*from   w w  w. j a v  a 2  s .  c  om*/

    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.jahia.tools.patches.SqlPatcher.java

private void execute(Resource r) {
    try {/* ww  w. ja  va 2s.  com*/
        logger.info("Executing script {}", r);
        DatabaseUtils.executeScript(new InputStreamReader(r.getInputStream(), Charsets.UTF_8));
        logger.info("Script {} executed successfully", r);
        rename(r, ".installed");
    } catch (Exception e) {
        logger.error("Execution of SQL script " + r + " failed with error: " + e.getMessage(), e);
        rename(r, ".failed");
    }
}

From source file:org.jamocha.logging.LayoutAdapter.java

public static PatternLayout createLayout(final Configuration config, final boolean plain) {
    return PatternLayout.createLayout(
            plain ? PatternLayout.DEFAULT_CONVERSION_PATTERN : PatternLayout.SIMPLE_CONVERSION_PATTERN,
            (PatternSelector) null, config, (RegexReplacement) null, Charsets.UTF_8, true, true, "", "");
}

From source file:org.jenkinsci.plugins.docker.commons.impl.UsernamePasswordDockerRegistryTokenSource.java

@NonNull
@Override/*from  www.j a v  a2s. c  o  m*/
public DockerRegistryToken convert(UsernamePasswordCredentials c) throws AuthenticationTokenException {
    return new DockerRegistryToken(c.getUsername(), Base64.encodeBase64String(
            (c.getUsername() + ":" + c.getPassword().getPlainText()).getBytes(Charsets.UTF_8)));
}