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

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

?? lockablefilewriter.java

?? < JavaME核心技術(shù)最佳實踐>>的全部源代碼
?? 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一区二区三区免费野_久草精品视频
中文乱码免费一区二区| 亚洲成av人片在www色猫咪| 欧美精品一区二区三区高清aⅴ| 欧美日韩精品欧美日韩精品一| 91麻豆国产自产在线观看| 99精品久久免费看蜜臀剧情介绍| 国产麻豆欧美日韩一区| 国产乱码精品一区二区三区五月婷| 免费高清在线视频一区·| 免费人成在线不卡| 精品制服美女丁香| 国产成人一级电影| 不卡欧美aaaaa| 欧亚一区二区三区| 欧美三日本三级三级在线播放| 欧美午夜精品久久久| 欧美精品国产精品| 精品乱人伦小说| 精品乱码亚洲一区二区不卡| 国产丝袜在线精品| 亚洲天天做日日做天天谢日日欢| 一区二区三区精品在线观看| 亚洲第一会所有码转帖| 欧美aaaaa成人免费观看视频| 极品瑜伽女神91| 成人爽a毛片一区二区免费| 91视频免费观看| 欧美一区二区三区喷汁尤物| 26uuu久久天堂性欧美| 亚洲欧洲99久久| 日韩精品视频网站| 国产91富婆露脸刺激对白| 91久久精品网| 欧美成人一区二区| 亚洲色图19p| 麻豆精品一二三| 99久久综合狠狠综合久久| 欧美片网站yy| 中文在线资源观看网站视频免费不卡| 亚洲欧美日韩电影| 蜜臀a∨国产成人精品| 成人精品小蝌蚪| 欧美老肥妇做.爰bbww视频| 久久日一线二线三线suv| 亚洲欧美日韩一区二区| 久久成人免费网| 欧美在线综合视频| 国产视频不卡一区| 午夜欧美2019年伦理| 高清不卡一二三区| 日韩一区二区在线观看| 国产精品女人毛片| 美女视频一区在线观看| 色婷婷激情久久| 国产日韩欧美麻豆| 人妖欧美一区二区| 91久久精品一区二区三区| 精品国产第一区二区三区观看体验 | 色偷偷久久一区二区三区| 欧美成人激情免费网| 一区二区高清视频在线观看| 国产一区二区不卡在线| 911精品国产一区二区在线| 国产精品日日摸夜夜摸av| 久久69国产一区二区蜜臀| 欧美三区在线视频| 1000部国产精品成人观看| 激情综合一区二区三区| 777欧美精品| 亚洲综合色噜噜狠狠| 国产99久久久久| 欧美videos中文字幕| 日韩有码一区二区三区| 在线观看亚洲一区| 亚洲手机成人高清视频| 国产成人免费av在线| 欧美白人最猛性xxxxx69交| 天堂蜜桃91精品| 欧美午夜寂寞影院| 一区二区三区高清不卡| 99这里只有久久精品视频| 欧美经典一区二区| 韩日精品视频一区| 欧美大片在线观看一区| 日韩经典中文字幕一区| 欧美午夜免费电影| 亚洲韩国精品一区| 91在线国产福利| 中文字幕亚洲一区二区av在线 | 日韩欧美一级二级三级| 亚洲bt欧美bt精品| 欧美午夜精品久久久久久超碰| 亚洲少妇屁股交4| 91丨porny丨首页| 亚洲婷婷国产精品电影人久久| va亚洲va日韩不卡在线观看| 国产亚洲精品中文字幕| 国产成人久久精品77777最新版本| 精品av久久707| 国产一本一道久久香蕉| 久久久久国产精品厨房| 国产精品主播直播| 久久精品无码一区二区三区| 紧缚捆绑精品一区二区| 久久欧美中文字幕| 国v精品久久久网| 国产精品乱人伦一区二区| proumb性欧美在线观看| 亚洲麻豆国产自偷在线| 精品视频一区二区三区免费| 亚洲高清免费观看| 欧美一区二区三区婷婷月色| 奇米在线7777在线精品| 精品动漫一区二区三区在线观看| 久久99精品久久久久久| 国产色一区二区| www.爱久久.com| 亚洲国产一区视频| 欧美一区二区国产| 国产精品一卡二卡| 中文字幕一区在线| 欧美色网一区二区| 久久成人18免费观看| 国产三级精品视频| 91污片在线观看| 午夜精品成人在线| 欧美成人猛片aaaaaaa| 国产福利精品导航| 亚洲三级电影网站| 在线不卡中文字幕播放| 寂寞少妇一区二区三区| 国产精品久久二区二区| 欧美日韩精品三区| 国产美女主播视频一区| 亚洲视频中文字幕| 日韩亚洲欧美成人一区| 顶级嫩模精品视频在线看| 一区二区三区在线影院| 日韩欧美黄色影院| av激情综合网| 日本伊人精品一区二区三区观看方式| 久久久久青草大香线综合精品| 色综合久久99| 久久se这里有精品| 亚洲日穴在线视频| 欧美成人一区二区三区在线观看| 不卡的电视剧免费网站有什么| 婷婷国产v国产偷v亚洲高清| 欧美—级在线免费片| 欧美高清视频www夜色资源网| 国产精品影视在线| 日韩在线播放一区二区| 国产精品三级av| 欧美va日韩va| 欧美综合天天夜夜久久| 国产一区二区三区美女| 亚洲二区视频在线| 中文字幕视频一区| 欧美zozo另类异族| 欧美色综合网站| www.欧美精品一二区| 久久国产综合精品| 亚洲午夜一二三区视频| 久久久久久久综合狠狠综合| 欧美日韩国产影片| a在线播放不卡| 激情小说亚洲一区| 日韩成人免费在线| 亚洲欧美国产高清| 日本一区二区三区四区| 日韩视频免费观看高清完整版在线观看 | 蜜臀av亚洲一区中文字幕| 日韩伦理免费电影| 欧美高清在线一区二区| 欧美成人在线直播| 这里只有精品99re| 在线视频欧美区| 91视频国产观看| 成人国产视频在线观看| 国产一区二区三区四区五区美女| 亚洲va国产天堂va久久en| 亚洲精品久久嫩草网站秘色| 久久精品视频网| 精品国产乱码久久| 欧美一区二区三区白人| 欧美日韩在线播| 欧洲国内综合视频| 91福利社在线观看| 91丨porny丨国产入口| av在线播放一区二区三区| 国产不卡高清在线观看视频| 国产在线精品一区二区夜色| 免费视频一区二区| 毛片一区二区三区| 石原莉奈在线亚洲二区| 婷婷六月综合网| 日本亚洲视频在线| 青娱乐精品视频在线| 免费成人小视频| 狠狠网亚洲精品|