Search in sources :

Example 46 with Enumeration

use of java.util.Enumeration in project atlas by alibaba.

the class ZipUtils method unzip.

public static void unzip(String zipFilename, String outputDirectory) throws IOException {
    File outFile = new File(outputDirectory);
    if (!outFile.exists()) {
        outFile.mkdirs();
    }
    if (!outFile.exists()) {
        throw new IOException("file not exist");
    }
    ZipFile zipFile = new ZipFile(zipFilename);
    Enumeration en = zipFile.entries();
    ZipEntry zipEntry = null;
    while (en.hasMoreElements()) {
        zipEntry = (ZipEntry) en.nextElement();
        if (zipEntry.isDirectory()) {
            String dirName = zipEntry.getName();
            dirName = dirName.substring(0, dirName.length() - 1);
            File f = new File(outFile.getPath() + File.separator + dirName);
            f.mkdirs();
        } else {
            String strFilePath = outFile.getPath() + File.separator + zipEntry.getName();
            File f = new File(strFilePath);
            // 判断文件不存在的话,就创建该文件所在文件夹的目录
            if (!f.exists()) {
                String[] arrFolderName = zipEntry.getName().split("/");
                String strRealFolder = "";
                for (int i = 0; i < (arrFolderName.length - 1); i++) {
                    strRealFolder += arrFolderName[i] + File.separator;
                }
                strRealFolder = outFile.getPath() + File.separator + strRealFolder;
                File tempDir = new File(strRealFolder);
                tempDir.mkdirs();
            }
            f.createNewFile();
            InputStream in = zipFile.getInputStream(zipEntry);
            FileOutputStream out = new FileOutputStream(f);
            try {
                int c;
                byte[] by = new byte[BUFFEREDSIZE];
                while ((c = in.read(by)) != -1) {
                    out.write(by, 0, c);
                }
                out.flush();
            } catch (IOException e) {
                throw e;
            } finally {
                closeQuitely(out);
                closeQuitely(in);
            }
        }
    }
    zipFile.close();
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 47 with Enumeration

use of java.util.Enumeration in project atlas by alibaba.

the class FileOperation method unZipAPk.

@SuppressWarnings("rawtypes")
public static void unZipAPk(String fileName, String filePath) throws IOException {
    checkDirectory(filePath);
    ZipFile zipFile = new ZipFile(fileName);
    Enumeration enumeration = zipFile.entries();
    try {
        while (enumeration.hasMoreElements()) {
            ZipEntry entry = (ZipEntry) enumeration.nextElement();
            if (entry.isDirectory()) {
                new File(filePath, entry.getName()).mkdirs();
                continue;
            }
            BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
            File file = new File(filePath + File.separator + entry.getName());
            File parentFile = file.getParentFile();
            if (parentFile != null && (!parentFile.exists())) {
                parentFile.mkdirs();
            }
            FileOutputStream fos = null;
            BufferedOutputStream bos = null;
            try {
                fos = new FileOutputStream(file);
                bos = new BufferedOutputStream(fos, TypedValue.BUFFER_SIZE);
                byte[] buf = new byte[TypedValue.BUFFER_SIZE];
                int len;
                while ((len = bis.read(buf, 0, TypedValue.BUFFER_SIZE)) != -1) {
                    fos.write(buf, 0, len);
                }
            } finally {
                if (bos != null) {
                    bos.flush();
                    bos.close();
                }
                if (bis != null) {
                    bis.close();
                }
            }
        }
    } finally {
        if (zipFile != null) {
            zipFile.close();
        }
    }
}
Also used : Enumeration(java.util.Enumeration) ZipFile(java.util.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ZipFile(java.util.zip.ZipFile) BufferedOutputStream(java.io.BufferedOutputStream)

Example 48 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class ServerTrustManager method getAcceptedIssuers.

@Override
public X509Certificate[] getAcceptedIssuers() {
    if (JiveGlobals.getBooleanProperty(ConnectionSettings.Server.TLS_ACCEPT_SELFSIGNED_CERTS, false)) {
        // Answer an empty list since we accept any issuer
        return new X509Certificate[0];
    } else {
        X509Certificate[] X509Certs = null;
        try {
            // See how many certificates are in the keystore.
            int numberOfEntry = trustStore.size();
            // If there are any certificates in the keystore.
            if (numberOfEntry > 0) {
                // Create an array of X509Certificates
                X509Certs = new X509Certificate[numberOfEntry];
                // Get all of the certificate alias out of the keystore.
                Enumeration aliases = trustStore.aliases();
                // Retrieve all of the certificates out of the keystore
                // via the alias name.
                int i = 0;
                while (aliases.hasMoreElements()) {
                    X509Certs[i] = (X509Certificate) trustStore.getCertificate((String) aliases.nextElement());
                    i++;
                }
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            X509Certs = null;
        }
        return X509Certs;
    }
}
Also used : Enumeration(java.util.Enumeration) X509Certificate(java.security.cert.X509Certificate) KeyStoreException(java.security.KeyStoreException) CertificateException(java.security.cert.CertificateException) GeneralSecurityException(java.security.GeneralSecurityException)

Example 49 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class ClientTrustManager method getAcceptedIssuers.

@Override
public X509Certificate[] getAcceptedIssuers() {
    if (JiveGlobals.getBooleanProperty("xmpp.client.certificate.accept-selfsigned", false)) {
        // Answer an empty list since we accept any issuer
        return new X509Certificate[0];
    } else {
        X509Certificate[] X509Certs = null;
        try {
            // See how many certificates are in the keystore.
            int numberOfEntry = trustStore.size();
            // If there are any certificates in the keystore.
            if (numberOfEntry > 0) {
                // Create an array of X509Certificates
                X509Certs = new X509Certificate[numberOfEntry];
                // Get all of the certificate alias out of the keystore.
                Enumeration aliases = trustStore.aliases();
                // Retrieve all of the certificates out of the keystore
                // via the alias name.
                int i = 0;
                while (aliases.hasMoreElements()) {
                    X509Certs[i] = (X509Certificate) trustStore.getCertificate((String) aliases.nextElement());
                    i++;
                }
            }
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
            X509Certs = null;
        }
        return X509Certs;
    }
}
Also used : Enumeration(java.util.Enumeration) X509Certificate(java.security.cert.X509Certificate) KeyStoreException(java.security.KeyStoreException) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CertPathBuilderException(java.security.cert.CertPathBuilderException) GeneralSecurityException(java.security.GeneralSecurityException) CertPathValidatorException(java.security.cert.CertPathValidatorException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CRLException(java.security.cert.CRLException)

Example 50 with Enumeration

use of java.util.Enumeration in project Openfire by igniterealtime.

the class BeanUtils method setProperties.

/**
     * Sets the properties of a Java Bean based on the request's properties. Because
     * this method has to know how to convert a String value into the correct type
     * for the bean, only a few bean property types are supported. They are: String,
     * boolean, int, long, float, double, Color, and Class.<p>
     *
     * If key/value pairs exist in the Map that don't correspond to properties
     * of the bean, they will be ignored.
     *
     * @param bean the JavaBean to set properties on.
     * @param request the HTTP request.
     */
public static void setProperties(Object bean, HttpServletRequest request) {
    for (Enumeration propNames = request.getParameterNames(); propNames.hasMoreElements(); ) {
        String propName = (String) propNames.nextElement();
        try {
            // Create a property descriptor for the named property. If
            // the bean doesn't have the named property, an
            // Introspection will be thrown.
            PropertyDescriptor descriptor = new PropertyDescriptor(propName, bean.getClass());
            // Load the class type of the property.
            Class propertyType = descriptor.getPropertyType();
            // Get the value of the property by converting it from a
            // String to the correct object type.
            Object value = decode(propertyType, request.getParameter(propName));
            // Set the value of the bean.
            descriptor.getWriteMethod().invoke(bean, value);
        } catch (IntrospectionException ie) {
        // Ignore. This exception means that the key in the map
        // does not correspond to a property of the bean.
        } catch (InvocationTargetException ite) {
        // Ignore. This exception most often occurs when a
        // value in the map is null and the target method doesn't
        // support null properties.
        } catch (IllegalAccessException e) {
            Log.error(e.getMessage(), e);
        } catch (Exception e) {
            Log.error(e.getMessage(), e);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) PropertyDescriptor(java.beans.PropertyDescriptor) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Enumeration (java.util.Enumeration)1179 IOException (java.io.IOException)202 ArrayList (java.util.ArrayList)141 File (java.io.File)102 HashMap (java.util.HashMap)86 Properties (java.util.Properties)85 Vector (java.util.Vector)83 List (java.util.List)77 HashSet (java.util.HashSet)65 Hashtable (java.util.Hashtable)63 Map (java.util.Map)59 Set (java.util.Set)59 URL (java.net.URL)57 ZipEntry (java.util.zip.ZipEntry)55 ServletContext (javax.servlet.ServletContext)53 Iterator (java.util.Iterator)50 InputStream (java.io.InputStream)47 ZipFile (java.util.zip.ZipFile)46 FileInputStream (java.io.FileInputStream)40 X509Certificate (java.security.cert.X509Certificate)37