📄 cachedfile.java
字号:
/*This file is part of JHttpServer.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.JHttpServer 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 JHttpServer; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA*/// Title : CachedFile.java// Version : 0.92// Copyright : Copyright (c) 2001// Author : Florent CUETO (fcueto@wanadoo.fr)// Description : A file in memory (cached)package jhttpserver;import java.io.*;public class CachedFile{ private byte[] fileContent; private String fileName; private long modificationDate; public CachedFile() { super(); fileName = null; fileContent = null; modificationDate = 0; } public void preloadFile(String fileName) throws IOException { if (fileContent != null) return; this.fileName = fileName; File f = new File(fileName); this.modificationDate = f.lastModified(); FileInputStream fis = new FileInputStream(f); BufferedInputStream bis = new BufferedInputStream(fis); ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[65536]; boolean cont = true; while(cont) { int read = bis.read(buffer, 0, 65536); if (read == -1) cont = false; else { baos.write(buffer, 0, read); } } baos.close(); bis.close(); fileContent = baos.toByteArray(); } public void flushFileCache() throws IOException { fileContent = null; preloadFile(fileName); } public byte[] getFileContent() { return(fileContent); } public long getModificationDate() { return modificationDate; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -