亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? fileutil.java

?? 解觖java技術中后臺無法上傳數給的情況
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * $Header: /cvsroot/mvnforum/myvietnam/src/net/myvietnam/mvncore/util/FileUtil.java,v 1.39 2006/04/15 02:59:20 minhnn Exp $
 * $Author: minhnn $
 * $Revision: 1.39 $
 * $Date: 2006/04/15 02:59:20 $
 *
 * ====================================================================
 *
 * Copyright (C) 2002-2006 by MyVietnam.net
 *
 * All copyright notices regarding MyVietnam and MyVietnam CoreLib
 * MUST remain intact in the scripts and source code.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Correspondence and Marketing Questions can be sent to:
 * info at MyVietnam net
 *
 * @author: Minh Nguyen  
 * @author: Mai  Nguyen  
 */
package net.myvietnam.mvncore.util;

import java.io.*;
import java.net.URL;
import java.text.DecimalFormat;

import net.myvietnam.mvncore.exception.BadInputException;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public final class FileUtil {

    private static Log log = LogFactory.getLog(FileUtil.class);

    private static FileUtil instance = new FileUtil();

    private static String servletClassesPath = null;

    private FileUtil() { // prevent instantiation
    }

    public static void checkGoodFilePath(String str) throws BadInputException {
        byte[] s = str.getBytes();
        int length = s.length;
        byte b = 0;

        for (int i = 0; i < length; i++) {
            b = s[i];
            if ((b == '*') ||
                (b == '?') ||
                (b == '<') ||
                (b == '>') ||
                (b == '"') ||
                (b == '|') ||
                (b == '\0')) {//null char : is it correct ????
                // not good char, throw an BadInputException
                //@todo : localize me
                throw new BadInputException("The string '" + DisableHtmlTagFilter.filter(str) + "' is not a good file path. Reason: character '" + (char)(b) + "' is not allowed.");
            }
        }// for
    }

    public static void checkGoodFileName(String str) throws BadInputException {
        // must be a good file path first
        checkGoodFilePath(str);
        byte[] s = str.getBytes();
        int length = s.length;
        byte b = 0;

        for (int i = 0; i < length; i++) {
            b = s[i];
            if ((b == '/') ||
                (b == '\\') ||
                (b == ':')) {
                // not good char, throw an BadInputException
                //@todo : localize me
                throw new BadInputException("The string '" + DisableHtmlTagFilter.filter(str) + "' is not a good file name. Reason: character '" + (char)(b) + "' is not allowed.");
            }
        }// for
    }

    public static void createDir(String dir, boolean ignoreIfExitst) throws IOException {
        File file = new File(dir);

        if (ignoreIfExitst && file.exists()) {
            return;
        }

        if ( file.mkdir() == false) {
            throw new IOException("Cannot create the directory = " + dir);
        }
    }

    public static void createDirs(String dir, boolean ignoreIfExitst) throws IOException {
        File file = new File(dir);

        if (ignoreIfExitst && file.exists()) {
            return;
        }

        if ( file.mkdirs() == false) {
            throw new IOException("Cannot create directories = " + dir);
        }
    }

    public static void deleteFile(String filename) throws IOException {
        File file = new File(filename);
        log.trace("Delete file = " + filename);
        if (file.isDirectory()) {
            throw new IOException("IOException -> BadInputException: not a file.");
        }
        if (file.exists() == false) {
            throw new IOException("IOException -> BadInputException: file is not exist.");
        }
        if (file.delete() == false) {
            throw new IOException("Cannot delete file. filename = " + filename);
        }
    }

    public static void deleteDir(File dir) throws IOException {
        if (dir.isFile()) throw new IOException("IOException -> BadInputException: not a directory.");
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                if (file.isFile()) {
                    file.delete();
                } else {
                    deleteDir(file);
                }
            }
        }//if
        dir.delete();
    }

    public static long getDirLength(File dir) throws IOException {
        if (dir.isFile()) throw new IOException("BadInputException: not a directory.");
        long size = 0;
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                long length = 0;
                if (file.isFile()) {
                    length = file.length();
                } else {
                    length = getDirLength(file);
                }
                size += length;
            }//for
        }//if
        return size;
    }

    public static long getDirLength_onDisk(File dir) throws IOException {
        if (dir.isFile()) throw new IOException("BadInputException: not a directory.");
        long size = 0;
        File[] files = dir.listFiles();
        if (files != null) {
            for (int i = 0; i < files.length; i++) {
                File file = files[i];
                long length = 0;
                if (file.isFile()) {
                    length = file.length();
                } else {
                    length = getDirLength_onDisk(file);
                }
                double mod = Math.ceil(((double)length)/512);
                if (mod == 0) mod = 1;
                length = ((long)mod) * 512;
                size += length;
            }
        }//if
        return size;
    }

    public static void emptyFile(String srcFilename) throws IOException {
        File srcFile = new File(srcFilename);
        if (!srcFile.exists()) {
            throw new FileNotFoundException("Cannot find the file: " + srcFile.getAbsolutePath());
        }
        if (!srcFile.canWrite()) {
            throw new IOException("Cannot write the file: " + srcFile.getAbsolutePath());
        }

        FileOutputStream outputStream = new FileOutputStream(srcFilename);
        outputStream.close();
    }

    public static void copyFile(String srcFilename, String destFilename, boolean overwrite) throws IOException {

        File srcFile = new File(srcFilename);
        if (!srcFile.exists()) {
            throw new FileNotFoundException("Cannot find the source file: " + srcFile.getAbsolutePath());
        }
        if (!srcFile.canRead()) {
            throw new IOException("Cannot read the source file: " + srcFile.getAbsolutePath());
        }

        File destFile = new File(destFilename);
        if (overwrite == false) {
            if (destFile.exists()) return;
        } else {
            if (destFile.exists()) {
                if (!destFile.canWrite()) {
                    throw new IOException("Cannot write the destination file: " + destFile.getAbsolutePath());
                }
            } else {
                if (!destFile.createNewFile()) {
                    throw new IOException("Cannot write the destination file: " + destFile.getAbsolutePath());
                }
            }
        }

        BufferedInputStream inputStream = null;
        BufferedOutputStream outputStream = null;
        byte[] block = new byte[1024];
        try {
            inputStream = new BufferedInputStream(new FileInputStream(srcFile));
            outputStream = new BufferedOutputStream(new FileOutputStream(destFile));
            while (true) {
                int readLength = inputStream.read(block);
                if (readLength == -1) break;// end of file
                outputStream.write(block, 0, readLength);
            }
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException ex) {
                    // just ignore
                }
            }
            if (outputStream != null) {
                try {
                    outputStream.close();
                } catch (IOException ex) {
                    // just ignore
                }
            }
        }
    }

    //@todo: why this method does not close the inputStream ???
    public static byte[] getBytes(InputStream inputStream) throws IOException {
        BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(1024);
        byte[] block = new byte[4096];
        while (true) {
            int readLength = bufferedInputStream.read(block);
            if (readLength == -1) break;// end of file
            byteArrayOutputStream.write(block, 0, readLength);
        }
        byte[] retValue = byteArrayOutputStream.toByteArray();
        byteArrayOutputStream.close();
        return retValue;
    }

    public static String getFileName(String fullFilePath) {
        if (fullFilePath == null) {
            return "";
        }
        int index1 = fullFilePath.lastIndexOf('/');
        int index2 = fullFilePath.lastIndexOf('\\');

        //index is the maximum value of index1 and index2
        int index = (index1 > index2) ? index1 : index2;
        if (index == -1) {
            // not found the path separator
            return fullFilePath;
        }
        String fileName = fullFilePath.substring(index + 1);
        return fileName;
    }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品久久久久久国产精华液| 久久网站热最新地址| 久久久不卡网国产精品二区| 国产精品视频线看| 国产成都精品91一区二区三| 欧美日韩免费视频| 自拍偷拍欧美激情| 色94色欧美sute亚洲13| 亚洲欧美偷拍三级| 91国模大尺度私拍在线视频 | xfplay精品久久| 另类调教123区| 精品国产一区二区三区久久久蜜月| 日本视频在线一区| 国产成人丝袜美腿| 亚洲一区二区偷拍精品| 欧美亚洲精品一区| 日日夜夜精品视频天天综合网| 91精品国产综合久久久蜜臀粉嫩| 久久精品国产一区二区| 中文字幕欧美日本乱码一线二线| av资源站一区| 欧美一区二区性放荡片| 国产一级精品在线| 91国偷自产一区二区三区观看| 美国十次综合导航| 国产农村妇女毛片精品久久麻豆| 97国产一区二区| 国产在线不卡一卡二卡三卡四卡| 天天综合色天天| 亚洲精品一区二区三区99| 91啪在线观看| 亚洲一区二区偷拍精品| 久久久影视传媒| 粉嫩av亚洲一区二区图片| 国产女主播视频一区二区| 欧美日韩精品一区二区三区蜜桃| 日本一区二区三级电影在线观看 | 日韩激情一二三区| 韩国三级电影一区二区| 色88888久久久久久影院野外| 日韩欧美国产wwwww| 一本到不卡精品视频在线观看| 精品夜夜嗨av一区二区三区| 奇米综合一区二区三区精品视频| 亚洲欧洲综合另类在线| 久久精品人人做人人综合| 国产又粗又猛又爽又黄91精品| 91麻豆精品国产91久久久使用方法 | 亚洲高清免费在线| 亚洲成a人片在线观看中文| 亚洲一区二区三区影院| 亚洲一区二区三区精品在线| 一区二区三区欧美| 亚洲v日本v欧美v久久精品| 欧美一区二区三区在线观看视频| 欧美曰成人黄网| 韩国毛片一区二区三区| 国产suv一区二区三区88区| 成人一道本在线| 色94色欧美sute亚洲线路一ni| 91国产丝袜在线播放| 蜜臀久久久久久久| 国产美女精品人人做人人爽 | 91免费国产在线观看| 免费在线观看一区二区三区| 精品一区二区三区久久| 成人av集中营| 欧美精品三级在线观看| 久久亚洲精品小早川怜子| 国产精品久久久久影视| 激情五月婷婷综合| 国产一区二区三区综合| 欧美综合视频在线观看| 欧美一卡二卡三卡| 亚洲婷婷综合久久一本伊一区 | 寂寞少妇一区二区三区| 色综合天天综合网天天狠天天 | 波多野结衣亚洲一区| 欧美日韩高清在线播放| 中文在线免费一区三区高中清不卡| 天堂蜜桃91精品| 欧美伊人精品成人久久综合97| 午夜不卡av免费| 成人午夜免费电影| 欧美一卡二卡三卡| 欧美一区二区三区四区五区| 日韩美女视频一区| 成人免费毛片a| 久久久久久一二三区| 日本不卡一区二区三区高清视频| 在线视频观看一区| 欧美日韩一级片在线观看| 国产欧美va欧美不卡在线| 国产农村妇女精品| 成人高清视频在线| 国产精品久久免费看| 激情综合五月天| 精品国产髙清在线看国产毛片| 欧美三级电影一区| jizzjizzjizz欧美| 亚洲男女一区二区三区| 午夜精品福利一区二区蜜股av| 亚洲视频每日更新| 99久久综合精品| 日本中文字幕一区二区有限公司| 久久久久久久久久看片| 欧美最猛黑人xxxxx猛交| 日韩电影在线一区二区三区| 制服丝袜日韩国产| 国产毛片精品国产一区二区三区| 欧美成人免费网站| 精品中文字幕一区二区| 国产亚洲精品久| 91久久人澡人人添人人爽欧美 | 欧美xxx久久| 粉嫩aⅴ一区二区三区四区 | 天天综合日日夜夜精品| 26uuu国产在线精品一区二区| 91欧美激情一区二区三区成人| 日韩va欧美va亚洲va久久| 1000部国产精品成人观看| 国产视频911| 欧美成人综合网站| 亚洲柠檬福利资源导航| 欧美zozozo| 欧美日韩在线播放三区| 国产高清久久久| 黄色日韩网站视频| 日韩高清在线一区| 国产河南妇女毛片精品久久久| 精品理论电影在线观看 | 欧美三级午夜理伦三级中视频| 中文字幕一区日韩精品欧美| 欧美一区二区黄| 欧美一级艳片视频免费观看| 欧美一区二区三区在线视频| 日韩一区二区三区视频在线| 欧美电视剧免费全集观看| 国产精品正在播放| 日韩在线观看一区二区| 久久蜜臀精品av| 欧美日韩久久久| 日韩欧美一级精品久久| 欧美一区二区三区在线观看视频| 精品奇米国产一区二区三区| 日韩精品成人一区二区在线| 一区二区三区久久| 一区在线中文字幕| 中文字幕一区二区三区不卡在线 | 久久综合色婷婷| 亚洲精品久久7777| 久久99深爱久久99精品| a4yy欧美一区二区三区| 欧美亚洲一区二区在线| 国产精品久久一级| 91超碰这里只有精品国产| 日韩视频在线一区二区| 成人性色生活片| 自拍偷拍国产精品| 亚洲乱码中文字幕综合| 黄色成人免费在线| 国产精品日韩成人| 中文字幕av一区二区三区| 国产精品毛片久久久久久久| 国产亚洲精品aa| 欧美tickle裸体挠脚心vk| 国产精品国产三级国产三级人妇 | 国产原创一区二区三区| 欧美三电影在线| 本田岬高潮一区二区三区| 精品裸体舞一区二区三区| 欧美激情艳妇裸体舞| 日韩一区欧美一区| 九九国产精品视频| 99精品桃花视频在线观看| 91麻豆成人久久精品二区三区| 欧美三级电影精品| 久久精品无码一区二区三区| 国产精品萝li| 99国产精品久| 色婷婷综合在线| 国产欧美精品一区| 蜜臀久久99精品久久久画质超高清| 欧美一级xxx| 亚洲男人电影天堂| 成人激情小说乱人伦| 国产激情一区二区三区桃花岛亚洲| 欧美三级欧美一级| 亚洲影院久久精品| 欧美一区二区视频在线观看| 国产精品传媒视频| 国产1区2区3区精品美女| 欧美撒尿777hd撒尿| 日韩视频一区二区三区| 蜜乳av一区二区| 91丨九色丨尤物| 日韩精品亚洲专区| 欧美高清在线一区二区| 色偷偷久久人人79超碰人人澡|