// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov. // Jad home page: http://www.geocities.com/kpdus/jad.html // Decompiler options: braces fieldsfirst space lnc package com.olio.communication.filetransfer; import com.olio.util.ALog; import java.io.BufferedInputStream; import java.io.File; import java.io.FileFilter; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; public class Utilities { protected static final char hexArray[] = "0123456789ABCDEF".toCharArray(); public Utilities() { } public static String bytesToHex(byte abyte0[]) { char ac[] = new char[abyte0.length * 2]; for (int i = 0; i < abyte0.length; i++) { int j = abyte0[i] & 0xff; ac[i * 2] = hexArray[j >>> 4]; ac[i * 2 + 1] = hexArray[j & 0xf]; } return new String(ac); } public static boolean clearDirectory(String s) { s = new File(s); if (s.exists() && s.isDirectory()) goto _L2; else goto _L1 _L1: ALog.e("Informed path isn't a directory - %s", new Object[] { s }); _L4: return false; _L2: s = s.listFiles(); if (s == null) { ALog.w("Passed in a file when clearing a directory.", new Object[0]); return false; } int j = s.length; int i = 0; label0: do { label1: { if (i >= j) { break label1; } if (!s[i].delete()) { break label0; } i++; } } while (true); if (true) goto _L4; else goto _L3 _L3: return true; } public static void closeInputStream(InputStream inputstream) { if (inputstream == null) { break MISSING_BLOCK_LABEL_8; } inputstream.close(); return; inputstream; inputstream.printStackTrace(); return; } public static void closeOutputStream(OutputStream outputstream) { if (outputstream == null) { break MISSING_BLOCK_LABEL_8; } outputstream.close(); return; outputstream; outputstream.printStackTrace(); return; } public static void copyFile(FileInputStream fileinputstream, FileOutputStream fileoutputstream) throws IOException { fileinputstream = fileinputstream.getChannel(); fileoutputstream = fileoutputstream.getChannel(); if (fileinputstream.transferTo(0L, fileinputstream.size(), fileoutputstream) != fileinputstream.size()) { ALog.e("Not all bytes transferred in copyfile", new Object[0]); } } public static boolean deleteDirectory(String s) { File file = new File(s); if (!file.exists() || !file.isDirectory()) { ALog.e("Informed path isn't a directory - %s", new Object[] { file }); return false; } boolean flag = clearDirectory(s); if (flag) { return file.delete(); } else { return flag; } } public static boolean deleteFile(String s) { File file = new File(s); if (file.isDirectory()) { return deleteDirectory(s); } if (file.exists()) { return file.delete(); } else { ALog.e("File not deleted because it doesn't exist: %s", new Object[] { s }); return false; } } public static File lastFileModified(String s) { s = new File(s); if (s != null && s.isDirectory()) { s = Arrays.asList(s.listFiles(new FileFilter() { public boolean accept(File file) { return file.isFile(); } })); if (s.size() > 0) { return (File)Collections.max(s, new Comparator() { public int compare(File file, File file1) { if (file.lastModified() < file1.lastModified()) { return -1; } return file != file1 ? 1 : 0; } public volatile int compare(Object obj, Object obj1) { return compare((File)obj, (File)obj1); } }); } } return null; } public static String md5Hash(FileInputStream fileinputstream) { MessageDigest messagedigest; byte abyte0[]; int i; try { messagedigest = MessageDigest.getInstance("MD5"); } // Misplaced declaration of an exception variable catch (FileInputStream fileinputstream) { ALog.e("Unable to calculate md5Hash", fileinputstream, new Object[0]); return null; } abyte0 = new byte[1024]; fileinputstream = new BufferedInputStream(fileinputstream); _L1: i = fileinputstream.read(abyte0); if (i <= 0) { break MISSING_BLOCK_LABEL_52; } messagedigest.update(abyte0, 0, i); goto _L1 fileinputstream; ALog.e("Error reading bytes when calculating md5Hash", fileinputstream, new Object[0]); return bytesToHex(messagedigest.digest()); } public static String md5Hash(byte abyte0[]) { MessageDigest messagedigest; try { messagedigest = MessageDigest.getInstance("MD5"); } // Misplaced declaration of an exception variable catch (byte abyte0[]) { ALog.e("Unable to calculate md5Hash", abyte0, new Object[0]); return null; } return bytesToHex(messagedigest.digest(abyte0)); } }