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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? lockablefilewriter.java

?? j2me簡單實例,j2me教程加源碼,希望大家喜歡
?? JAVA
字號:
/*
 * Copyright 2001-2004 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.output;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;

/**
 * FileWriter that will create and honor lock files to allow simple
 * cross thread file lock handling.
 * <p>
 * This class provides a simple alternative to <code>FileWriter</code>
 * that will use a lock file to prevent duplicate writes.
 * <p>
 * By default, the file will be overwritten, but this may be changed to append.
 * The lock directory may be specified, but defaults to the system property
 * <code>java.io.tmpdir</code>.
 * The encoding may also be specified, and defaults to the platform default.
 *
 * @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
 * @author <a href="mailto:ms@collab.net">Michael Salmon</a>
 * @author <a href="mailto:jon@collab.net">Jon S. Stevens</a>
 * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a>
 * @author Stephen Colebourne
 * @author Andy Lehane
 * @version $Id: LockableFileWriter.java 385293 2006-03-12 15:11:19Z scolebourne $
 */
public class LockableFileWriter extends Writer {
    // Cannot extend ProxyWriter, as requires writer to be
    // known when super() is called

    /** The extension for the lock file. */
    private static final String LCK = ".lck";

    /** The writer to decorate. */
    private final Writer out;
    /** The lock file. */
    private final File lockFile;

    /**
     * Constructs a LockableFileWriter.
     * If the file exists, it is overwritten.
     *
     * @param fileName  the file to write to, not null
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(String fileName) throws IOException {
        this(fileName, false, null);
    }

    /**
     * Constructs a LockableFileWriter.
     *
     * @param fileName  file to write to, not null
     * @param append  true if content should be appended, false to overwrite
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(String fileName, boolean append) throws IOException {
        this(fileName, append, null);
    }

    /**
     * Constructs a LockableFileWriter.
     *
     * @param fileName  the file to write to, not null
     * @param append  true if content should be appended, false to overwrite
     * @param lockDir  the directory in which the lock file should be held
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(String fileName, boolean append, String lockDir) throws IOException {
        this(new File(fileName), append, lockDir);
    }

    /**
     * Constructs a LockableFileWriter.
     * If the file exists, it is overwritten.
     *
     * @param file  the file to write to, not null
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(File file) throws IOException {
        this(file, false, null);
    }

    /**
     * Constructs a LockableFileWriter.
     *
     * @param file  the file to write to, not null
     * @param append  true if content should be appended, false to overwrite
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(File file, boolean append) throws IOException {
        this(file, append, null);
    }

    /**
     * Constructs a LockableFileWriter.
     *
     * @param file  the file to write to, not null
     * @param append  true if content should be appended, false to overwrite
     * @param lockDir  the directory in which the lock file should be held
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(File file, boolean append, String lockDir) throws IOException {
        this(file, null, append, lockDir);
    }

    /**
     * Constructs a LockableFileWriter with a file encoding.
     *
     * @param file  the file to write to, not null
     * @param encoding  the encoding to use, null means platform default
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(File file, String encoding) throws IOException {
        this(file, encoding, false, null);
    }

    /**
     * Constructs a LockableFileWriter with a file encoding.
     *
     * @param file  the file to write to, not null
     * @param encoding  the encoding to use, null means platform default
     * @param append  true if content should be appended, false to overwrite
     * @param lockDir  the directory in which the lock file should be held
     * @throws NullPointerException if the file is null
     * @throws IOException in case of an I/O error
     */
    public LockableFileWriter(File file, String encoding, boolean append,
            String lockDir) throws IOException {
        super();
        // init file to create/append
        file = file.getAbsoluteFile();
        if (file.getParentFile() != null) {
            FileUtils.forceMkdir(file.getParentFile());
        }
        if (file.isDirectory()) {
            throw new IOException("File specified is a directory");
        }
        
        // init lock file
        if (lockDir == null) {
            lockDir = System.getProperty("java.io.tmpdir");
        }
        File lockDirFile = new File(lockDir);
        FileUtils.forceMkdir(lockDirFile);
        testLockDir(lockDirFile);
        lockFile = new File(lockDirFile, file.getName() + LCK);
        
        // check if locked
        createLock();
        
        // init wrapped writer
        out = initWriter(file, encoding, append);
    }

    //-----------------------------------------------------------------------
    /**
     * Tests that we can write to the lock directory.
     *
     * @param lockDir  the File representing the lock directory
     * @throws IOException if we cannot write to the lock directory
     * @throws IOException if we cannot find the lock file
     */
    private void testLockDir(File lockDir) throws IOException {
        if (!lockDir.exists()) {
            throw new IOException(
                    "Could not find lockDir: " + lockDir.getAbsolutePath());
        }
        if (!lockDir.canWrite()) {
            throw new IOException(
                    "Could not write to lockDir: " + lockDir.getAbsolutePath());
        }
    }

    /**
     * Creates the lock file.
     *
     * @throws IOException if we cannot create the file
     */
    private void createLock() throws IOException {
        synchronized (LockableFileWriter.class) {
            if (!lockFile.createNewFile()) {
                throw new IOException("Can't write file, lock " +
                        lockFile.getAbsolutePath() + " exists");
            }
            lockFile.deleteOnExit();
        }
    }

    /**
     * Initialise the wrapped file writer.
     * Ensure that a cleanup occurs if the writer creation fails.
     *
     * @param file  the file to be accessed
     * @param encoding  the encoding to use
     * @param append  true to append
     * @throws IOException if an error occurs
     */
    private Writer initWriter(File file, String encoding, boolean append) throws IOException {
        boolean fileExistedAlready = file.exists();
        OutputStream stream = null;
        Writer writer = null;
        try {
            if (encoding == null) {
                writer = new FileWriter(file.getAbsolutePath(), append);
            } else {
                stream = new FileOutputStream(file.getAbsolutePath(), append);
                writer = new OutputStreamWriter(stream, encoding);
            }
        } catch (IOException ex) {
            IOUtils.closeQuietly(writer);
            IOUtils.closeQuietly(stream);
            lockFile.delete();
            if (fileExistedAlready == false) {
                file.delete();
            }
            throw ex;
        } catch (RuntimeException ex) {
            IOUtils.closeQuietly(writer);
            IOUtils.closeQuietly(stream);
            lockFile.delete();
            if (fileExistedAlready == false) {
                file.delete();
            }
            throw ex;
        }
        return writer;
    }

    //-----------------------------------------------------------------------
    /**
     * Closes the file writer.
     *
     * @throws IOException if an I/O error occurs
     */
    public void close() throws IOException {
        try {
            out.close();
        } finally {
            lockFile.delete();
        }
    }

    //-----------------------------------------------------------------------
    /** @see java.io.Writer#write(int) */
    public void write(int idx) throws IOException {
        out.write(idx);
    }

    /** @see java.io.Writer#write(char[]) */
    public void write(char[] chr) throws IOException {
        out.write(chr);
    }

    /** @see java.io.Writer#write(char[], int, int) */
    public void write(char[] chr, int st, int end) throws IOException {
        out.write(chr, st, end);
    }

    /** @see java.io.Writer#write(String) */
    public void write(String str) throws IOException {
        out.write(str);
    }

    /** @see java.io.Writer#write(String, int, int) */
    public void write(String str, int st, int end) throws IOException {
        out.write(str, st, end);
    }

    /** @see java.io.Writer#flush() */
    public void flush() throws IOException {
        out.flush();
    }

}

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
久久国产人妖系列| 成人精品视频一区二区三区| 欧美极品xxx| 欧美区在线观看| 国产成人免费高清| 日韩福利电影在线观看| 最新久久zyz资源站| 日韩亚洲欧美在线| 在线亚洲高清视频| 成人一区二区在线观看| 久久国产剧场电影| 天天色图综合网| 国产精品久久99| 欧美精品一区二区三区在线| 欧美老肥妇做.爰bbww| 不卡电影免费在线播放一区| 久久99精品国产麻豆不卡| 亚洲国产精品久久人人爱| 日本一区免费视频| 久久青草欧美一区二区三区| 91精品欧美综合在线观看最新 | 欧美日韩国产综合一区二区 | 日韩一区二区不卡| 欧美美女喷水视频| 一本大道久久a久久精品综合| 高清久久久久久| 国产伦精品一区二区三区视频青涩| 日韩电影免费在线看| 亚洲成人动漫精品| 一区二区三区欧美日| 亚洲欧美视频一区| 亚洲欧洲日产国产综合网| 国产精品另类一区| 国产精品欧美经典| 国产精品毛片久久久久久| 日本一区二区综合亚洲| 国产女主播一区| 国产欧美日韩三区| 国产欧美日韩三级| 国产精品狼人久久影院观看方式| 国产精品丝袜一区| 国产精品护士白丝一区av| 国产精品网曝门| 亚洲免费观看视频| 亚洲国产精品一区二区久久| 午夜欧美一区二区三区在线播放| 亚洲午夜久久久| 日韩精品免费专区| 免费精品视频最新在线| 国产在线国偷精品产拍免费yy| 精品一区二区三区的国产在线播放| 麻豆成人91精品二区三区| 久久成人免费网站| 久久国产成人午夜av影院| 国产一区二区视频在线| 成人免费视频播放| 91免费在线看| 欧美日韩亚洲综合一区二区三区| 欧美人动与zoxxxx乱| 日韩一区二区精品| 久久精品人人做人人爽人人| 国产精品成人免费在线| 亚洲精品美腿丝袜| 视频一区二区三区在线| 六月丁香综合在线视频| 成人高清伦理免费影院在线观看| 91免费国产在线观看| 欧美性猛片xxxx免费看久爱| 欧美一区二区精品| 日本一区二区电影| 亚洲大片免费看| 国产精品主播直播| 在线一区二区三区四区五区| 日韩一区二区三区在线| 国产精品第四页| 偷窥少妇高潮呻吟av久久免费| 国精产品一区一区三区mba视频| a在线播放不卡| 欧美一区二区视频观看视频| wwww国产精品欧美| 亚洲黄色片在线观看| 蜜桃免费网站一区二区三区| 成人午夜免费电影| 欧美剧情电影在线观看完整版免费励志电影 | 亚洲一区二区成人在线观看| 免费观看在线色综合| www.亚洲在线| 日韩女同互慰一区二区| 亚洲视频免费观看| 九色|91porny| 欧洲一区二区三区免费视频| 欧美xxxxxxxxx| 洋洋av久久久久久久一区| 国产精品99久久不卡二区| 欧美午夜精品一区| 国产精品水嫩水嫩| 麻豆精品视频在线| 色哟哟精品一区| 中文一区在线播放| 日本亚洲三级在线| 在线欧美日韩精品| 中文字幕高清不卡| 久久99精品久久久久久国产越南| 欧美在线看片a免费观看| 国产拍欧美日韩视频二区| 日韩成人免费在线| 91网站最新网址| 久久亚洲影视婷婷| 麻豆国产精品777777在线| 欧美在线一区二区| 亚洲欧洲日韩一区二区三区| 国产一区在线不卡| 日韩视频一区在线观看| 亚洲成人综合在线| 色噜噜狠狠色综合中国| 国产精品乱码人人做人人爱| 国产黄色成人av| 久久伊99综合婷婷久久伊| 老汉av免费一区二区三区 | 欧美日韩国产一二三| 亚洲四区在线观看| 成人精品电影在线观看| 2023国产精品| 国产一区视频导航| 日韩精品最新网址| 日韩电影一区二区三区四区| 欧美日韩一区二区电影| 亚洲高清视频中文字幕| 欧美日韩一区在线观看| 亚洲综合一二三区| 91久久精品一区二区| 亚洲欧美另类久久久精品| 色综合久久六月婷婷中文字幕| 国产精品久久久一本精品 | 久久综合视频网| 国产专区综合网| 久久蜜桃一区二区| 国产suv精品一区二区883| 亚洲国产精品成人综合| av激情综合网| 亚洲视频一区二区在线| 91丨九色丨蝌蚪富婆spa| 亚洲视频电影在线| 在线观看免费视频综合| 亚洲风情在线资源站| 欧美疯狂性受xxxxx喷水图片| 日韩成人午夜电影| 精品国产一区二区三区不卡| 国产麻豆精品在线| 亚洲欧洲成人av每日更新| 色综合天天天天做夜夜夜夜做| 亚洲综合男人的天堂| 88在线观看91蜜桃国自产| 免费在线观看视频一区| 精品久久久三级丝袜| 国产91丝袜在线播放九色| 亚洲视频在线一区| 欧美精品一级二级| 精彩视频一区二区| 国产精品免费aⅴ片在线观看| 色综合久久综合| 免费成人深夜小野草| 中文字幕乱码亚洲精品一区| 91欧美一区二区| 热久久国产精品| 国产精品丝袜一区| 欧美日本在线一区| 国产麻豆成人精品| 亚洲综合丝袜美腿| 日韩精品中文字幕一区二区三区 | 国产精品资源在线看| 亚洲乱码国产乱码精品精可以看| 欧美日韩一本到| 国产福利一区二区| 亚洲国产你懂的| 久久久99精品免费观看不卡| 91年精品国产| 久久国产尿小便嘘嘘| 亚洲青青青在线视频| 日韩精品中文字幕一区二区三区 | 久久看人人爽人人| 在线视频一区二区免费| 韩国av一区二区三区在线观看| 亚洲三级在线观看| 欧美成人激情免费网| 日本乱人伦一区| 狠狠网亚洲精品| 亚洲国产中文字幕| 中文字幕欧美国产| 日韩一级二级三级| 色丁香久综合在线久综合在线观看| 男人的天堂久久精品| 亚洲免费观看高清完整版在线观看 | 亚洲精品高清在线观看| www一区二区| 欧美浪妇xxxx高跟鞋交| 91在线精品一区二区三区| 激情丁香综合五月| 亚洲高清免费视频| 中文字幕亚洲一区二区av在线 |