All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hibegin.http.server.util.FileCacheKit Maven / Gradle / Ivy

Go to download

Simple, flexible, less dependent, more extended. Less memory footprint, can quickly build Web project. Can quickly run embedded, Android devices

There is a newer version: 0.3.162
Show newest version
package com.hibegin.http.server.util;

import com.hibegin.common.util.IOUtil;

import java.io.File;
import java.io.IOException;
import java.util.Objects;

public class FileCacheKit {

    public static final String SERVER_WEB_SERVER_TEMP_FILE_PREFIX = "sws-cache-";

    public static File generatorRequestTempFile(String flag, byte[] bytes) throws IOException {
        File file = File.createTempFile(SERVER_WEB_SERVER_TEMP_FILE_PREFIX, suffix(flag), new File(PathUtil.getTempPath()));
        if (Objects.nonNull(bytes) && bytes.length > 0) {
            IOUtil.writeBytesToFile(bytes, file);
        } else {
            IOUtil.writeBytesToFile(new byte[0], file);
        }
        return file;
    }

    public static String suffix(String flag) {
        return ".tmp." + flag;
    }

    public static void cleanByFlag(int flag) {
        File[] files = new File(PathUtil.getTempPath()).listFiles();
        if (files != null) {
            for (File file : files) {
                if (file.getName().startsWith(SERVER_WEB_SERVER_TEMP_FILE_PREFIX) && file.getName().contains(suffix(flag + ""))) {
                    file.delete();
                }
            }
        }
    }

    public static boolean deleteCache(File file) {
        return file.delete();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy