Java Properties Load from File loadProperties(JarFile enclosedJarFile, String jarEntryPath)

Here you can find the source of loadProperties(JarFile enclosedJarFile, String jarEntryPath)

Description

Loads the properties file residing inside a jar.

License

Open Source License

Parameter

Parameter Description
enclosedJarFile the enclosed jar file
jarEntryPath the jar entry path

Exception

Parameter Description
IOException This is a special case where we want the consumers tocontinue without failures, because most of the cases consumesthis in a loop.

Return

the properties

Declaration

public static Properties loadProperties(JarFile enclosedJarFile, String jarEntryPath) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2006-2010 eBay Inc. All Rights Reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *******************************************************************************/

import java.io.IOException;
import java.io.InputStream;

import java.util.Properties;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class Main {
    /**/* ww  w.  j a  v a 2s  .co m*/
     * Loads the properties file residing inside a jar. The enclosed jar file is
     * queried for the given jar entry path and is parsed into a properties
     * file. Most of the cases this is being used to load some SOA properties
     * file from a jar project which is not imported to the workspace but is
     * stored somewhere in the file system. But any client who wants to load a
     * properties file can use this. There is nothing SOA specific here in this
     * API.
     *
     * @param enclosedJarFile the enclosed jar file
     * @param jarEntryPath the jar entry path
     * @return the properties
     * @throws IOException This is a special case where we want the consumers to
     * continue without failures, because most of the cases consumes
     * this in a loop.
     */
    public static Properties loadProperties(JarFile enclosedJarFile, String jarEntryPath) throws IOException {
        JarEntry jarEntry = enclosedJarFile.getJarEntry(jarEntryPath);
        InputStream inputStream = enclosedJarFile.getInputStream(jarEntry);
        Properties properties = new Properties();
        properties.load(inputStream);
        return properties;

    }
}

Related

  1. loadProperties(final File f)
  2. loadProperties(final File propertiesFile)
  3. loadProperties(final String file)
  4. loadProperties(final String fileName)
  5. loadProperties(final ZipFile file, final ZipEntry ze)
  6. loadProperties(Map map, File file, String encoding)
  7. loadProperties(ProcessingEnvironment env, String fileName)
  8. loadProperties(Properties properties, File file)
  9. loadProperties(Properties properties, File propertyFile)