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

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

?? filesystemutils.java

?? < JavaME核心技術最佳實踐>>的全部源代碼
?? JAVA
字號:
/*
 * Copyright 2005-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.commons.io;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.StringTokenizer;

/**
 * General File System utilities.
 * <p>
 * This class provides static utility methods for general file system
 * functions not provided via the JDK {@link java.io.File File} class.
 * <p>
 * The current functions provided are:
 * <ul>
 * <li>Get the free space on a drive
 * </ul>
 *
 * @author Frank W. Zammetti
 * @author Stephen Colebourne
 * @author Thomas Ledoux
 * @version $Id: FileSystemUtils.java 385680 2006-03-13 22:27:09Z scolebourne $
 * @since Commons IO 1.1
 */
public class FileSystemUtils {

    /** Singleton instance, used mainly for testing. */
    private static final FileSystemUtils INSTANCE = new FileSystemUtils();

    /** Operating system state flag for error. */
    private static final int INIT_PROBLEM = -1;
    /** Operating system state flag for neither Unix nor Windows. */
    private static final int OTHER = 0;
    /** Operating system state flag for Windows. */
    private static final int WINDOWS = 1;
    /** Operating system state flag for Unix. */
    private static final int UNIX = 2;

    /** The operating system flag. */
    private static final int OS;
    static {
        int os = OTHER;
        try {
            String osName = System.getProperty("os.name");
            if (osName == null) {
                throw new IOException("os.name not found");
            }
            osName = osName.toLowerCase();
            // match
            if (osName.indexOf("windows") != -1) {
                os = WINDOWS;
            } else if (osName.indexOf("linux") != -1 ||
                osName.indexOf("sun os") != -1 ||
                osName.indexOf("sunos") != -1 ||
                osName.indexOf("solaris") != -1 ||
                osName.indexOf("mpe/ix") != -1 ||
                osName.indexOf("hp-ux") != -1 ||
                osName.indexOf("aix") != -1 ||
                osName.indexOf("freebsd") != -1 ||
                osName.indexOf("irix") != -1 ||
                osName.indexOf("digital unix") != -1 ||
                osName.indexOf("unix") != -1 ||
                osName.indexOf("mac os x") != -1) {
                os = UNIX;
            } else {
                os = OTHER;
            }

        } catch (Exception ex) {
            os = INIT_PROBLEM;
        }
        OS = os;
    }

    /**
     * Instances should NOT be constructed in standard programming.
     */
    public FileSystemUtils() {
        super();
    }

    //-----------------------------------------------------------------------
    /**
     * Returns the free space on a drive or volume by invoking
     * the command line.
     * This method does not normalize the result, and typically returns
     * bytes on Windows, 512 byte units on OS X and kilobytes on Unix.
     * <p>
     * See also {@link #freeSpaceKb(String)} for a better implementation
     * which normalizes to kilobytes.
     * <p>
     * Note that some OS's are NOT currently supported, including OS/390.
     * <pre>
     * FileSystemUtils.freeSpace("C:");       // Windows
     * FileSystemUtils.freeSpace("/volume");  // *nix
     * </pre>
     * The free space is calculated via the command line.
     * It uses 'dir /-c' on Windows and 'df' on *nix.
     *
     * @param path  the path to get free space for, not null, not empty on Unix
     * @return the amount of free drive space on the drive or volume
     * @throws IllegalArgumentException if the path is invalid
     * @throws IllegalStateException if an error occurred in initialisation
     * @throws IOException if an error occurs when finding the free space
     */
    public static long freeSpace(String path) throws IOException {
        return INSTANCE.freeSpaceOS(path, OS, false);
    }

    //-----------------------------------------------------------------------
    /**
     * Returns the free space on a drive or volume in kilobytes by invoking
     * the command line.
     * Note that some OS's are NOT currently supported, including OS/390.
     * <pre>
     * FileSystemUtils.freeSpaceKb("C:");       // Windows
     * FileSystemUtils.freeSpaceKb("/volume");  // *nix
     * </pre>
     * The free space is calculated via the command line.
     * It uses 'dir /-c' on Windows and 'df -k' on *nix.
     *
     * @param path  the path to get free space for, not null, not empty on Unix
     * @return the amount of free drive space on the drive or volume in kilobytes
     * @throws IllegalArgumentException if the path is invalid
     * @throws IllegalStateException if an error occurred in initialisation
     * @throws IOException if an error occurs when finding the free space
     * @since Commons IO 1.2
     */
    public static long freeSpaceKb(String path) throws IOException {
        return INSTANCE.freeSpaceOS(path, OS, true);
    }

    //-----------------------------------------------------------------------
    /**
     * Returns the free space on a drive or volume in a cross-platform manner.
     * Note that some OS's are NOT currently supported, including OS/390.
     * <pre>
     * FileSystemUtils.freeSpace("C:");  // Windows
     * FileSystemUtils.freeSpace("/volume");  // *nix
     * </pre>
     * The free space is calculated via the command line.
     * It uses 'dir /-c' on Windows and 'df' on *nix.
     *
     * @param path  the path to get free space for, not null, not empty on Unix
     * @param os  the operating system code
     * @param kb  whether to normalize to kilobytes
     * @return the amount of free drive space on the drive or volume
     * @throws IllegalArgumentException if the path is invalid
     * @throws IllegalStateException if an error occurred in initialisation
     * @throws IOException if an error occurs when finding the free space
     */
    long freeSpaceOS(String path, int os, boolean kb) throws IOException {
        if (path == null) {
            throw new IllegalArgumentException("Path must not be empty");
        }
        switch (os) {
            case WINDOWS:
                return (kb ? freeSpaceWindows(path) / 1024 : freeSpaceWindows(path));
            case UNIX:
                return freeSpaceUnix(path, kb);
            case OTHER:
                throw new IllegalStateException("Unsupported operating system");
            default:
                throw new IllegalStateException(
                  "Exception caught when determining operating system");
        }
    }

    /**
     * Find free space on the Windows platform using the 'dir' command.
     *
     * @param path  the path to get free space for, including the colon
     * @return the amount of free drive space on the drive
     * @throws IOException if an error occurs
     */
    long freeSpaceWindows(String path) throws IOException {
        path = FilenameUtils.normalize(path);
        if (path.length() > 2 && path.charAt(1) == ':') {
            path = path.substring(0, 2);  // seems to make it work
        }

        // build and run the 'dir' command
        String[] cmdAttrbs = new String[] {"cmd.exe", "/C", "dir /-c " + path};

        // read in the output of the command to an ArrayList
        BufferedReader in = null;
        String line = null;
        ArrayList lines = new ArrayList();
        try {
            in = openProcessStream(cmdAttrbs);
            line = in.readLine();
            while (line != null) {
                line = line.toLowerCase().trim();
                lines.add(line);
                line = in.readLine();
            }
        } finally {
            IOUtils.closeQuietly(in);
        }

        if (lines.size() == 0) {
            // unknown problem, throw exception
            throw new IOException(
                    "Command line 'dir /c' did not return any info " +
                    "for command '" + cmdAttrbs[2] + "'");
        }

        // now iterate over the lines we just read and find the LAST
        // non-empty line (the free space bytes should be in the last element
        // of the ArrayList anyway, but this will ensure it works even if it's
        // not, still assuming it is on the last non-blank line)
        long bytes = -1;
        int i = lines.size() - 1;
        int bytesStart = 0;
        int bytesEnd = 0;
        outerLoop: while (i > 0) {
            line = (String) lines.get(i);
            if (line.length() > 0) {
                // found it, so now read from the end of the line to find the
                // last numeric character on the line, then continue until we
                // find the first non-numeric character, and everything between
                // that and the last numeric character inclusive is our free
                // space bytes count
                int j = line.length() - 1;
                innerLoop1: while (j >= 0) {
                    char c = line.charAt(j);
                    if (Character.isDigit(c)) {
                      // found the last numeric character, this is the end of
                      // the free space bytes count
                      bytesEnd = j + 1;
                      break innerLoop1;
                    }
                    j--;
                }
                innerLoop2: while (j >= 0) {
                    char c = line.charAt(j);
                    if (!Character.isDigit(c) && c != ',' && c != '.') {
                      // found the next non-numeric character, this is the
                      // beginning of the free space bytes count
                      bytesStart = j + 1;
                      break innerLoop2;
                    }
                    j--;
                }
                break outerLoop;
            }
        }

        // remove commas and dots in the bytes count
        StringBuffer buf = new StringBuffer(line.substring(bytesStart, bytesEnd));
        for (int k = 0; k < buf.length(); k++) {
            if (buf.charAt(k) == ',' || buf.charAt(k) == '.') {
                buf.deleteCharAt(k--);
            }
        }
        bytes = Long.parseLong(buf.toString());
        return bytes;
    }

    /**
     * Find free space on the *nix platform using the 'df' command.
     *
     * @param path  the path to get free space for
     * @param kb  whether to normalize to kilobytes
     * @return the amount of free drive space on the volume
     * @throws IOException if an error occurs
     */
    long freeSpaceUnix(String path, boolean kb) throws IOException {
        if (path.length() == 0) {
            throw new IllegalArgumentException("Path must not be empty");
        }
        path = FilenameUtils.normalize(path);

        // build and run the 'dir' command
        String[] cmdAttribs = 
            (kb ? new String[] {"df", "-k", path} : new String[] {"df", path});

        // read the output from the command until we come to the second line
        long bytes = -1;
        BufferedReader in = null;
        try {
            in = openProcessStream(cmdAttribs);
            String line1 = in.readLine(); // header line (ignore it)
            String line2 = in.readLine(); // the line we're interested in
            String line3 = in.readLine(); // possibly interesting line
            if (line2 == null) {
                // unknown problem, throw exception
                throw new IOException(
                        "Command line 'df' did not return info as expected " +
                        "for path '" + path +
                        "'- response on first line was '" + line1 + "'");
            }
            line2 = line2.trim();

            // Now, we tokenize the string. The fourth element is what we want.
            StringTokenizer tok = new StringTokenizer(line2, " ");
            if (tok.countTokens() < 4) {
                // could be long Filesystem, thus data on third line
                if (tok.countTokens() == 1 && line3 != null) {
                    line3 = line3.trim();
                    tok = new StringTokenizer(line3, " ");
                } else {
                    throw new IOException(
                            "Command line 'df' did not return data as expected " +
                            "for path '" + path + "'- check path is valid");
                }
            } else {
                tok.nextToken(); // Ignore Filesystem
            }
            tok.nextToken(); // Ignore 1K-blocks
            tok.nextToken(); // Ignore Used
            String freeSpace = tok.nextToken();
            try {
                bytes = Long.parseLong(freeSpace);
            } catch (NumberFormatException ex) {
                throw new IOException(
                        "Command line 'df' did not return numeric data as expected " +
                        "for path '" + path + "'- check path is valid");
            }

        } finally {
            IOUtils.closeQuietly(in);
        }

        if (bytes < 0) {
            throw new IOException(
                    "Command line 'df' did not find free space in response " +
                    "for path '" + path + "'- check path is valid");
        }
        return bytes;
    }

    /**
     * Opens the stream to be operating system.
     *
     * @param params  the command parameters
     * @return a reader
     * @throws IOException if an error occurs
     */
    BufferedReader openProcessStream(String[] params) throws IOException {
        Process proc = Runtime.getRuntime().exec(params);
        return new BufferedReader(
            new InputStreamReader(proc.getInputStream()));
    }

}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩片之四级片| 欧美日高清视频| 久久99国产精品尤物| 蜜桃久久久久久久| 久久99在线观看| 91小视频在线免费看| 欧美私模裸体表演在线观看| 欧美亚洲日本国产| 91麻豆产精品久久久久久| 91精品办公室少妇高潮对白| 94-欧美-setu| 日韩一级完整毛片| 国产精品久久久久久福利一牛影视| 337p粉嫩大胆色噜噜噜噜亚洲| 国产婷婷色一区二区三区| 国内不卡的二区三区中文字幕 | 亚洲在线视频一区| 不卡欧美aaaaa| 日韩一区二区免费在线电影| 欧美va在线播放| 亚洲综合色婷婷| 久久69国产一区二区蜜臀| 国产精品一二三| 欧美体内she精视频| 国产偷国产偷精品高清尤物| 国产一区二区三区在线看麻豆| 欧美视频一区二区三区四区| 亚洲视频你懂的| 成人一区在线观看| 国产精品久久久久久户外露出 | 欧美一二三四在线| 免费三级欧美电影| 26uuu亚洲| 懂色av中文字幕一区二区三区| 国产三级欧美三级| 国产成人免费在线视频| 国产精品毛片久久久久久久| 成人性视频免费网站| 亚洲色欲色欲www| 欧美日韩免费一区二区三区| 午夜精品福利视频网站| 2020国产精品自拍| 99久久精品国产一区二区三区| 亚洲人123区| 日韩精品中午字幕| 成人午夜视频在线观看| 亚洲免费av在线| 欧美一区二区三区四区高清| 国产成人免费视频一区| 亚洲成人资源网| 中文字幕成人在线观看| 精品视频全国免费看| 国精品**一区二区三区在线蜜桃| 综合激情成人伊人| 9191精品国产综合久久久久久| 国精产品一区一区三区mba视频| 亚洲免费大片在线观看| 久久久777精品电影网影网| 欧美午夜精品久久久| 成人a区在线观看| 久久激情综合网| 五月天欧美精品| 亚洲视频精选在线| 日本一区二区三区视频视频| 日韩欧美国产系列| 777a∨成人精品桃花网| 一本久道久久综合中文字幕 | 国产区在线观看成人精品| 欧美日韩一区成人| 91久久精品日日躁夜夜躁欧美| 国产精品一级黄| 国产凹凸在线观看一区二区| 老汉av免费一区二区三区| 亚洲午夜精品久久久久久久久| 一级日本不卡的影视| 亚洲精品你懂的| 亚洲成a人片在线观看中文| 亚洲自拍另类综合| 免费观看成人av| 极品少妇xxxx精品少妇偷拍| 韩日精品视频一区| 国产酒店精品激情| 成人爽a毛片一区二区免费| 成人av在线看| 欧美午夜在线观看| 欧美丰满高潮xxxx喷水动漫| 精品女同一区二区| 中文字幕va一区二区三区| 中文字幕一区二区三| 天堂av在线一区| 国产精品亚洲人在线观看| 91免费看视频| 精品粉嫩aⅴ一区二区三区四区| 国产精品午夜电影| 午夜精品久久久久久| 国产乱色国产精品免费视频| fc2成人免费人成在线观看播放 | 亚洲一区二区欧美| 国产一区二区三区| 欧美色涩在线第一页| 久久影院午夜论| 亚洲第一二三四区| 国产电影一区二区三区| 欧美日韩国产成人在线91| 中文一区在线播放| 美国十次了思思久久精品导航| 成人黄色在线看| 精品国产免费人成在线观看| 一区二区三区加勒比av| 丁香六月久久综合狠狠色| 91精选在线观看| 五月激情六月综合| 一道本成人在线| 国产精品久久久爽爽爽麻豆色哟哟| 老司机精品视频导航| 在线观看视频一区二区欧美日韩| 国产欧美综合色| 欧美撒尿777hd撒尿| 亚洲激情成人在线| 欧美视频在线播放| 亚洲国产精品久久不卡毛片| 色婷婷av一区二区三区gif| 国产精品成人免费在线| 成人av资源下载| 亚洲狠狠丁香婷婷综合久久久| 不卡一区二区在线| 自拍偷拍国产亚洲| 一本大道久久a久久综合| 一区二区三区不卡视频在线观看 | 一区二区三区精品| 欧美吞精做爰啪啪高潮| 丝袜美腿亚洲综合| 欧美一区二区三区日韩视频| 狂野欧美性猛交blacked| 精品少妇一区二区三区视频免付费 | 成人avav在线| 亚洲国产人成综合网站| 欧美一区二区三区视频免费 | 国产日韩精品一区二区三区 | 亚洲婷婷国产精品电影人久久| 9i在线看片成人免费| 亚洲综合男人的天堂| 欧美成人一区二区三区片免费| 风间由美一区二区av101| 亚洲高清在线精品| 国产视频911| 欧美日韩在线免费视频| 精品一区二区三区免费观看 | 精品99久久久久久| 欧洲国内综合视频| 成人一二三区视频| 老司机免费视频一区二区| 国产精品国产馆在线真实露脸| 欧美一区二区三区在线视频| 成人爱爱电影网址| 国产盗摄女厕一区二区三区| 久久精品72免费观看| 亚洲一区在线观看网站| 亚洲人成网站色在线观看| 国产日韩欧美电影| 国产午夜亚洲精品午夜鲁丝片| 51精品久久久久久久蜜臀| 91黄色免费看| 欧美亚洲一区二区三区四区| 日韩精品综合一本久道在线视频| 欧美群妇大交群中文字幕| 欧美亚洲尤物久久| 6080午夜不卡| 久久日韩精品一区二区五区| 欧美精品一区二区久久久| 精品1区2区在线观看| 精品国产123| 久久久精品免费观看| 欧美国产乱子伦| 亚洲黄色在线视频| 免费在线视频一区| 国产精品一区久久久久| 不卡影院免费观看| 欧美日韩国产成人在线91| 日韩三级电影网址| 欧美激情一区二区三区在线| 亚洲色图欧美激情| 亚洲va国产va欧美va观看| 日本女优在线视频一区二区| 国产盗摄视频一区二区三区| 色综合天天在线| 欧美人动与zoxxxx乱| 久久中文字幕电影| 亚洲激情av在线| 国产**成人网毛片九色 | 国产综合久久久久久鬼色| 91理论电影在线观看| 精品少妇一区二区三区免费观看| 日韩一区中文字幕| 麻豆国产精品777777在线| 91久久精品一区二区三| 久久蜜桃一区二区| 亚洲第一主播视频| 在线观看91精品国产入口| 久久精品一区蜜桃臀影院|