Search in sources :

Example 51 with FilenameFilter

use of java.io.FilenameFilter in project GT by Tencent.

the class LogController method setLastestLogFileAsCurFile.

private void setLastestLogFileAsCurFile() {
    // 遍历日志文件夹中的日志文件,取最新的为当前写目标
    if (!curLogFolder.exists()) {
        curLogFolder.mkdirs();
    }
    // 过滤出合法的日志文件
    File[] files = curLogFolder.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File dir, String filename) {
            return filename.matches(LogUtils.LOG_FILE_MATCHE);
        }
    });
    // 按修改时间排序
    if (null != files && files.length > 0) {
        Arrays.sort(files, 0, files.length, new Comparator<File>() {

            @Override
            public int compare(File lhs, File rhs) {
                return lhs.lastModified() <= rhs.lastModified() ? 1 : -1;
            }
        });
        // 取最新的文件为当前文件
        curFile = files[0];
    } else {
        curFile = new File(curLogFolder, 00 + LogUtils.LOG_POSFIX);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) File(java.io.File)

Example 52 with FilenameFilter

use of java.io.FilenameFilter in project GT by Tencent.

the class GTGPSUtils method getGPSFileList.

public static ArrayList<String> getGPSFileList() {
    ArrayList<String> arrFile = new ArrayList<String>();
    try {
        File[] files = Env.ROOT_GPS_FOLDER.listFiles(new FilenameFilter() {

            @Override
            public boolean accept(File dir, String filename) {
                if (filename != null && filename.endsWith(".gps")) {
                    return true;
                }
                return false;
            }
        });
        if (files != null) {
            // 文件个数
            int count = files.length;
            for (int i = 0; i < count; i++) {
                File file = files[i];
                arrFile.add(file.getName());
            }
        } else {
            arrFile.add("empty");
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return arrFile;
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File)

Example 53 with FilenameFilter

use of java.io.FilenameFilter in project ice by Netflix.

the class MapDb method upload.

void upload() {
    AmazonS3Client s3Client = AwsUtils.getAmazonS3Client();
    File dir = new File(config.localDir);
    File[] files = dir.listFiles(new FilenameFilter() {

        public boolean accept(File file, String fileName) {
            return fileName.startsWith(dbName);
        }
    });
    for (File file : files) s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + file.getName(), file);
    for (File file : files) s3Client.putObject(config.workS3BucketName, config.workS3BucketPrefix + "copy" + file.getName(), file);
}
Also used : FilenameFilter(java.io.FilenameFilter) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) File(java.io.File)

Example 54 with FilenameFilter

use of java.io.FilenameFilter in project atlas by alibaba.

the class Framework method restoreFromExistedBundle.

/**
     *         boolean lockSuccess = false;
     try {
     lockSuccess = BundleLock.ReadLock(location);
     if (location == null){
     return null;
     }
     Bundle bundle = bundles.get(location);
     if(bundle==null) {
     bundle = restoreFromExistedBundle(location);
     }
     return bundle;

     }finally {
     if(lockSuccess) {
     try {
     BundleLock.ReadUnLock(location);
     }catch(Throwable e){}
     }
     }
     * @param location
     * @return
     */
public static BundleImpl restoreFromExistedBundle(final String location) {
    boolean lockSuccess = false;
    File bundleDir = new File(STORAGE_LOCATION, location);
    BundleImpl bundle = null;
    // just restore
    if (bundleDir.exists() && new File(bundleDir, "meta").exists()) {
        try {
            lockSuccess = BundleLock.ReadLock(location);
            AtlasFileLock.getInstance().LockExclusive(bundleDir);
            BundleContext impl = new BundleContext();
            if (BaselineInfoManager.instance().dexPatchVersion() > 0 && BaselineInfoManager.instance().isDexPatched(location)) {
                impl.dexPatchVersion = BaselineInfoManager.instance().dexPatchVersion();
                bundle = new BundleImpl(bundleDir, impl);
                if (bundle != null) {
                    bundle.optDexFile();
                }
            } else {
                String[] versions = bundleDir.list(new FilenameFilter() {

                    @Override
                    public boolean accept(File dir, String filename) {
                        return filename.startsWith(BundleArchive.REVISION_DIRECTORY);
                    }
                });
                if (versions != null && versions.length > 0) {
                    bundle = new BundleImpl(bundleDir, impl);
                    if (bundle != null) {
                        bundle.optDexFile();
                    }
                }
            }
        } catch (Exception e) {
            if (e instanceof BundleArchive.MisMatchException) {
                if (bundleDir.exists()) {
                    bundle = null;
                }
            }
            AtlasMonitor.getInstance().trace(AtlasMonitor.BUNDLE_INSTALL_FAIL, location, AtlasMonitor.RESTORED_FAILED_MSG, FileUtils.getDataAvailableSpace());
            Log.e("Framework", "restore bundle failed" + location, e);
        } finally {
            if (lockSuccess) {
                try {
                    BundleLock.ReadUnLock(location);
                } catch (Throwable e) {
                }
            }
            AtlasFileLock.getInstance().unLock(bundleDir);
        }
    }
    return bundle;
}
Also used : FilenameFilter(java.io.FilenameFilter) BundleArchive(android.taobao.atlas.framework.bundlestorage.BundleArchive) File(java.io.File) BundleException(org.osgi.framework.BundleException) LowDiskException(android.taobao.atlas.runtime.LowDiskException) IOException(java.io.IOException)

Example 55 with FilenameFilter

use of java.io.FilenameFilter in project atlas by alibaba.

the class Framework method mergeWalsDir.

private static void mergeWalsDir(File walsDir, File storageDir) {
    if (writeAheads != null && writeAheads.size() > 0) {
        for (int i = 0; i < writeAheads.size(); i++) {
            if (writeAheads.get(i) == null) {
                continue;
            }
            File walDir = new File(walsDir, writeAheads.get(i));
            try {
                if (walDir != null && walDir.exists()) {
                    // merge wal dir to storage
                    final File[] walBundleDirs = walDir.listFiles();
                    if ((walBundleDirs != null) && (walBundleDirs.length > 0)) {
                        for (File walBundleDir : walBundleDirs) {
                            if (walBundleDir.isDirectory()) {
                                File bundleDir = new File(storageDir, walBundleDir.getName());
                                //                                    if (bundleDir.exists()) {
                                //                                        deleteDirectory(bundleDir);
                                //                                    }
                                File newRevDir = new File(walBundleDir, "version.1");
                                if (!newRevDir.exists()) {
                                    return;
                                }
                                File[] revisions = bundleDir.listFiles(new FilenameFilter() {

                                    @Override
                                    public boolean accept(File dir, String filename) {
                                        return filename.startsWith(BundleArchive.REVISION_DIRECTORY);
                                    }
                                });
                                int targetREV = 1;
                                List<String> useless = new ArrayList<>();
                                File latestRevision = null;
                                String targetVersion = BundleArchive.REVISION_DIRECTORY + ".1";
                                int rev;
                                if (revisions != null && revisions.length > 0) {
                                    for (File revision : revisions) {
                                        if ((rev = Integer.parseInt(revision.getName().substring(8))) >= targetREV) {
                                            targetREV = rev;
                                            if (!new File(revision, BundleArchive.DEPRECATED_MARK).exists()) {
                                                if (latestRevision != null) {
                                                    useless.add(latestRevision.getName());
                                                }
                                                latestRevision = revision;
                                            }
                                        } else {
                                            useless.add(revision.getName());
                                        }
                                        if (new File(revision, BundleArchive.DEPRECATED_MARK).exists()) {
                                            useless.add(revision.getName());
                                        }
                                    }
                                    if (!BaselineInfoManager.instance().isCachePreVersion()) {
                                        useless.add(latestRevision.getName());
                                    }
                                    targetVersion = BundleArchive.REVISION_DIRECTORY + "." + (++targetREV);
                                }
                                File targetDir = new File(bundleDir, targetVersion);
                                targetDir.mkdirs();
                                File meta = new File(bundleDir, "meta");
                                if (meta.exists()) {
                                    meta.delete();
                                }
                                new File(walBundleDir, "meta").renameTo(meta);
                                // move bundle to storage
                                boolean result = newRevDir.renameTo(targetDir);
                                if (!result || !targetDir.exists()) {
                                    targetDir.mkdirs();
                                    result = newRevDir.renameTo(targetDir);
                                    new File(walBundleDir, "meta").renameTo(meta);
                                    if (!result || !targetDir.exists() || !meta.exists()) {
                                        BaselineInfoManager.instance().rollbackHardly();
                                        android.os.Process.killProcess(android.os.Process.myPid());
                                    }
                                } else {
                                    //remove old bundles
                                    for (String uselessDir : useless) {
                                        File uselessFile = new File(bundleDir, uselessDir);
                                        if (uselessFile.exists()) {
                                            deleteDirectory(uselessFile);
                                        }
                                        if (uselessFile.exists()) {
                                            new File(uselessFile, BundleArchive.DEPRECATED_MARK).createNewFile();
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                writeAheads.set(i, null);
            } catch (Exception e) {
                Log.e("Framework", "Error while merge wal dir", e);
            }
        }
    }
    if (walsDir.exists()) {
        deleteDirectory(walsDir);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) ArrayList(java.util.ArrayList) File(java.io.File) BundleException(org.osgi.framework.BundleException) LowDiskException(android.taobao.atlas.runtime.LowDiskException) IOException(java.io.IOException)

Aggregations

FilenameFilter (java.io.FilenameFilter)402 File (java.io.File)398 IOException (java.io.IOException)100 ArrayList (java.util.ArrayList)72 Test (org.junit.Test)60 URL (java.net.URL)22 List (java.util.List)22 RandomAccessFile (java.io.RandomAccessFile)19 HashSet (java.util.HashSet)17 FileOutputStream (java.io.FileOutputStream)14 JarFile (java.util.jar.JarFile)14 FileNotFoundException (java.io.FileNotFoundException)13 MalformedURLException (java.net.MalformedURLException)13 HashMap (java.util.HashMap)13 FileFilter (java.io.FileFilter)11 FileWriter (java.io.FileWriter)11 ZipFile (java.util.zip.ZipFile)11 TestClient (org.syncany.tests.util.TestClient)11 FileReader (java.io.FileReader)10 Pattern (java.util.regex.Pattern)10