Exemplo n.º 1
0
 public void close() {
   FileUtil.close(socket);
   FileUtil.close(in);
   FileUtil.close(out);
   socket = null;
   in = null;
   out = null;
 }
Exemplo n.º 2
0
 public String loadText() {
   File file = getPropertyFile();
   InputStream fin = null;
   try {
     fin = new FileInputStream(file);
     byte[] buff = FileUtil.readAll(fin);
     return new String(buff);
   } catch (Exception e) {
   } finally {
     FileUtil.close(fin);
   }
   return null;
 }
Exemplo n.º 3
0
 public synchronized boolean reload(boolean force) {
   long now = System.currentTimeMillis();
   if (force == false && now < last_check + 3000) return false;
   last_check = now;
   File file = getPropertyFile();
   if (file.lastModified() == last_load_time) {
     return false;
   }
   last_load_time = file.lastModified();
   Properties temp = new Properties();
   if (file.canRead()) {
     FileInputStream in = null;
     try {
       in = new FileInputStream(file);
       temp.load(in);
     } catch (Exception e) {
       e.printStackTrace();
     } finally {
       FileUtil.close(in);
     }
   }
   property = ConfigValueUtil.replaceSysProp(temp);
   apply();
   ConfObserver.run();
   return true;
 }
Exemplo n.º 4
0
 public boolean saveText(String text) {
   File file = getPropertyFile();
   OutputStream out = null;
   try {
     out = new FileOutputStream(file);
     out.write(text.getBytes());
     return true;
   } catch (Exception e) {
   } finally {
     FileUtil.close(out);
   }
   return false;
 }
Exemplo n.º 5
0
 static {
   try {
     String patch = Configure.getInstance().direct_patch_class;
     String[] files = StringUtil.tokenizer(patch, ",;");
     for (int i = 0; files != null && i < files.length; i++) {
       byte[] bytes = FileUtil.readAll(new File(files[i]));
       if (bytes != null) {
         String classname = getClassName(bytes);
         if (classname != null) {
           classPatchMap.put(classname, bytes);
         }
       }
     }
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
Exemplo n.º 6
0
  private void open(String path) throws FileNotFoundException, IOException {
    this.path = path;
    this.file = new File(this.path + ".hfile");
    boolean isNew = this.file.exists() == false || this.file.length() < _memHeadReserved;

    if (isNew) {
      this.memBuffer = new byte[_memHeadReserved + memBufferSize];
      this.memBuffer[0] = (byte) 0xCA;
      this.memBuffer[1] = (byte) 0xFE;
    } else {
      this.memBufferSize = (int) (this.file.length() - _memHeadReserved);
      this.memBuffer = FileUtil.readAll(this.file);
      this.count = DataInputX.toInt(this.memBuffer, _countPos);
    }

    FlushCtr.getInstance().regist(this);
  }
Exemplo n.º 7
0
  public void run() {
    while (running) {
      RequestInfo r = queue.get();
      BufferedWriter bw = null;
      try {
        File file = getFile();

        bw = new BufferedWriter(new FileWriter(file, true));
        bw.write(r.toString());
        bw.newLine();
        // bw.flush();
      } catch (Throwable e) {
        outFile = null;
        e.printStackTrace();
      } finally {
        FileUtil.close(bw);
      }
    }
  }
Exemplo n.º 8
0
 private static void process(String arg) throws Exception {
   long stime = System.currentTimeMillis();
   try {
     URL u = new URL(arg);
     URLConnection uc = u.openConnection();
     String uu = setUser(uc);
     uc.connect();
     InputStream o = uc.getInputStream();
     FileUtil.readAll(o);
     Map<String, List<String>> heads = uc.getHeaderFields();
     List<String> cookie = heads.get("Set-Cookie");
     keepCookie("" + cookie);
     o.close();
     long dur = System.currentTimeMillis() - stime;
     System.out.println(arg + " " + dur + " ms " + uu);
   } catch (Exception e) {
     long dur = System.currentTimeMillis() - stime;
     System.out.println(arg + " " + dur + " ms - ERROR");
   }
 }
Exemplo n.º 9
0
 public void close() {
   if (this.channel != null) {
     FileUtil.close(this.channel);
   }
   FileUtil.close(this.file);
 }
Exemplo n.º 10
0
 public synchronized void flush() {
   FileUtil.save(this.file, this.memBuffer);
   this.dirty = false;
 }