diskaccess.java

来自「SOCK VIA HTTP是通过HTTP建立通道的SOCK」· Java 代码 · 共 92 行

JAVA
92
字号
/*This file is part of Socks via HTTP.This package is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.Socks via HTTP is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with Socks via HTTP; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/// Title :        DiskAccess.java// Version :      0.40// Copyright :    Copyright (c) 2001// Author :       Florent CUETO (fcueto@wanadoo.fr)// Description :  Disk Access (writing)package socks4;import java.io.*;// Multithreaded file writerpublic class DiskAccess extends Thread{  // Members  private String fileName = null; // Filename  private String string = null;   // String to write  private FileWriter fw = null;   // File  // Constructor  public DiskAccess(String fileName, String string)  {    this.fileName = fileName;    this.string = string;  }  public void run()  {    //    boolean success = false;    int cpt = 0;    // Try to write the file    // Stop condition:    // 1 - Write successful    // 2 - Max number of retries over    while((!success) && (cpt < 6))    {      try      {        if (fw == null)        {          fw = new FileWriter(fileName, true);        }        // Timestamp the log        // Add a carriage return        fw.write(new java.util.Date().toString() + " : " + string + "\r\n");        // Flush the file        fw.flush();        // Close the file        fw.close();        fw = null;        // Operation OK        success = true;      }      catch(IOException e)      {        // Sleep for a while        // and retry        try        {          this.sleep(500);        }        catch(InterruptedException ex){}        cpt++;      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?