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();
}
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();
}
}
}
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;
}
}
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;
}
}
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);
}
}
}
Aggregations