001package com.hfg.util.io; 002 003import java.io.File; 004import java.io.InputStream; 005import java.io.FileInputStream; 006import java.io.IOException; 007import java.io.BufferedInputStream; 008import java.io.OutputStream; 009import java.util.Calendar; 010import java.util.Date; 011import java.util.GregorianCalendar; 012import java.net.HttpURLConnection; 013import java.net.URL; 014 015 016//------------------------------------------------------------------------------ 017/** 018 * Implementation of RemoteFile for file system files 019 * 020 * @author J. Alex Taylor, hairyfatguy.com 021 */ 022//------------------------------------------------------------------------------ 023// com.hfg XML/HTML Coding Library 024// 025// This library is free software; you can redistribute it and/or 026// modify it under the terms of the GNU Lesser General Public 027// License as published by the Free Software Foundation; either 028// version 2.1 of the License, or (at your option) any later version. 029// 030// This library is distributed in the hope that it will be useful, 031// but WITHOUT ANY WARRANTY; without even the implied warranty of 032// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 033// Lesser General Public License for more details. 034// 035// You should have received a copy of the GNU Lesser General Public 036// License along with this library; if not, write to the Free Software 037// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 038// 039// J. Alex Taylor, President, Founder, CEO, COO, CFO, OOPS hairyfatguy.com 040// jataylor@hairyfatguy.com 041//------------------------------------------------------------------------------ 042 043 044public class FileSystemRemoteFile extends AbstractRemoteFile 045{ 046 047 //########################################################################### 048 // PRIVATE FIELDS 049 //########################################################################### 050 051 private File mFile; 052 private String mRequestedFilePath; 053 054 //########################################################################### 055 // CONSTRUCTORS 056 //########################################################################### 057 058 //--------------------------------------------------------------------------- 059 public FileSystemRemoteFile(File inFile) 060 { 061 mFile = inFile; 062 } 063 064 065 //########################################################################### 066 // PUBLIC METHODS 067 //########################################################################### 068 069 //--------------------------------------------------------------------------- 070 @Override 071 public String getName() 072 { 073 return mFile.getName(); 074 } 075 076 //--------------------------------------------------------------------------- 077 @Override 078 public String getPath() 079 { 080 return mFile.getPath(); 081 } 082 083 //--------------------------------------------------------------------------- 084 public FileSystemRemoteFile setRequestedPath(String inValue) 085 { 086 mRequestedFilePath = inValue; 087 return this; 088 } 089 090 //--------------------------------------------------------------------------- 091 @Override 092 public String getRequestedPath() 093 { 094 return mRequestedFilePath != null ? mRequestedFilePath : getPath(); 095 } 096 097 //--------------------------------------------------------------------------- 098 @Override 099 public String getURL() 100 { 101 return mFile.getPath(); 102 } 103 104 //--------------------------------------------------------------------------- 105 @Override 106 public long getSize() 107 { 108 return mFile.length(); 109 } 110 111 //--------------------------------------------------------------------------- 112 @Override 113 public Calendar getTimestamp() 114 { 115 Calendar timestamp = new GregorianCalendar(); 116 timestamp.setTime(new Date(mFile.lastModified())); 117 118 return timestamp; 119 } 120 121 //--------------------------------------------------------------------------- 122 @Override 123 public InputStream getInputStream() 124 throws IOException 125 { 126 return new BufferedInputStream(new FileInputStream(mFile)); 127 } 128 129}