001package org.opengion.fukurou.model; 002 003import java.io.File; 004import java.io.FileFilter; 005import java.io.FileNotFoundException; 006import java.io.IOException; 007import java.io.InputStream; 008 009/** 010 * CloudFileOperation用のファイル情報の格納クラス 011 * 012 * listFilesで取得した、ディレクトリとファイル一覧情報を格納します。 013 * 014 * パフォーマンスや分かりやすさを考慮してCloudFileOperationからは分離しています 015 * 016 * @og.group ファイル操作 017 * 018 * @og.rev 5.10.8.0 (2019/02/01) 新規作成 019 * @og.rev 5.10.9.0 (2019/03/01) 変更対応 020 * @author oota 021 * @since JDK7.0 022 */ 023public class FileOperationInfo extends CloudFileOperation { 024 //* このプログラムのVERSION文字列を設定します。{@VALUE} */ 025 private static final String VERSION = "8.0.0.0 (2021/07/31)" ; 026 private static final long serialVersionUID = 800020210731L ; 027 028 /** クラス変数 */ 029 private final String plugin; 030 031 private long size; 032 // 8.0.0.0 (2021/07/31) Field ** has the same name as a method 033// private long lastModified; 034// private boolean isFile; 035// private boolean isDirectory; 036 private long lastTime; 037 private boolean isFil; 038 private boolean isDir; 039 private FileOperation file; 040 041 /** 042 * コンストラクタ 043 * 044 * 生成時の初期処理。 045 * 046 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 047 * 048 * @param plugin プラグイン名 049 * @param bucket バケット名 050 * @param path ファイルパス 051 */ 052 public FileOperationInfo(final String plugin, final String bucket, final String path) { 053 super(bucket, path); 054 this.plugin = plugin; 055 size = 0; 056// lastModified = 0; 057// isFile = false; 058// isDirectory = false; 059 lastTime = 0L; 060 isFil = false; 061 isDir = false; 062 file = null; 063 } 064 065 /** 066 * FileOperationクラスの生成 067 * 068 * 呼び出し時に、FileOperationインスタンスが未生成の場合は、 069 * 生成を行います。 070 */ 071 private void setFileOperation() { 072 if(file == null) { 073 file = FileOperationFactory.newStorageOperation( plugin, conBucket, conPath ); 074 } 075 } 076 077 /** Method */ 078 /** 079 * 書き込み処理 080 * 081 * InputStreamのデータを書き込みます。 082 * 083 * @param is 書き込みデータのInputStream 084 * @throws IOException ファイル関連エラー情報 085 */ 086 @Override 087 public void write(final InputStream is) throws IOException { 088 setFileOperation(); 089 file.write(is); 090 } 091 092 /** 093 * 読み込み処理 094 * 095 * データを読み込み、InputStreamとして、返します。 096 * 097 * @return 読み込みデータのInputStream 098 * @throws FileNotFoundException ファイル非存在エラー情報 099 */ 100 @Override 101 public InputStream read() throws FileNotFoundException { 102 setFileOperation(); 103 return file.read(); 104 } 105 106 /** 107 * 削除処理 108 * 109 * ファイルを削除します。 110 * 111 * @return 成否フラグ 112 */ 113 @Override 114 public boolean delete() { 115 setFileOperation(); 116 return file.delete(); 117 } 118 119 /** 120 * コピー処理 121 * 122 * ファイルを指定先に、コピーします。 123 * 124 * @param afPath コピー先 125 * @return 成否フラグ 126 */ 127 @Override 128 public boolean copy(final String afPath) { 129 setFileOperation(); 130 return file.copy(afPath); 131 } 132 133 /** 134 * 一覧取得 135 * 136 * 1つ下の、ディレクトリ・ファイル一覧を取得します。 137 * 138 * @param filter フィルタ情報 139 * @return ファイル一覧 140 */ 141 @Override 142 public File[] listFiles(final FileFilter filter) { 143 setFileOperation(); 144 return file.listFiles(filter); 145 } 146 147 /** 148 * ファイルサイズ取得 149 * 150 * ファイルサイズを取得します。 151 * 152 * @return ファイルサイズ 153 */ 154 @Override 155 public long length() { 156 return size; 157 } 158 159 /** 160 * ファイルサイズ設定 161 * 162 * ファイルサイズを設定します。 163 * 164 * @param size ファイルサイズ 165 */ 166 public void setSize(final long size) { 167 this.size = size; 168 } 169 170 /** 171 * 最終更新時刻の取得 172 * 173 * 最終更新時刻を取得します。 174 * 175 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 176 * 177 * @return 最終更新時刻 178 */ 179 @Override 180 public long lastModified() { 181// return lastModified; 182 return lastTime; 183 } 184 185 /** 186 * 最終更新時刻の設定 187 * 188 * 最終更新時刻を設定します。 189 * 190 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 191 * 192 * @param lastModified 最終更新時刻 193 */ 194 public void setLastModifiedValue(final long lastModified) { 195// this.lastModified = lastModified; 196 lastTime = lastModified; 197 } 198 199 /** 200 * ファイル判定取得 201 * 202 * ファイルであるかの判定を返します。 203 * 204 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 205 * 206 * @return ファイル判定 207 */ 208 @Override 209 public boolean isFile() { 210// return isFile; 211 return isFil; 212 } 213 214 /** 215 * ファイル判定設定 216 * 217 * ファイルであるかの判定を設定します。 218 * 219 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 220 * 221 * @param isFile ファイル判定 222 */ 223 public void setFile(final boolean isFile) { 224// this.isFile = isFile; 225 isFil = isFile; 226 } 227 228 /** 229 * ディレクトリ判定取得 230 * 231 * ディレクトリであるかの判定を返します。 232 * 233 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 234 * 235 * @return ディレクトリ判定 236 */ 237 @Override 238 public boolean isDirectory() { 239// return isDirectory; 240 return isDir; 241 } 242 243 /** 244 * ディレクトリ判定設定 245 * 246 * ディレクトリであるかの判定を設定します。 247 * 248 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 249 * 250 * @param isDirectory ディレクトリ判定 251 */ 252 public void setDirectory(final boolean isDirectory) { 253// this.isDirectory = isDirectory; 254 isDir = isDirectory; 255 } 256 257 /** 258 * 親情報の取得 259 * 260 * 親情報を返します。 261 * 262 * @return 親情報 263 */ 264 @Override 265 public File getParentFile() { 266 return FileOperationFactory.newStorageOperation( file , this.getParent() ); 267 } 268 269// /** 270// * このオブジェクトと他のオブジェクトが等しいかどうかを示します。 271// * インタフェース Comparable の 実装に関連して、再定義しています。 272// * 273// * @og.rev 7.2.9.4 (2020/11/20) spotbugs:スーパークラスの equals メソッドをオーバーライドしていないクラス 274// * 275// * @param object 比較対象の参照オブジェクト 276// * 277// * @return 引数に指定されたオブジェクトとこのオブジェクトが等しい場合は true、そうでない場合は false 278// */ 279// @Override 280// public boolean equals( final Object object ) { 281// return object instanceof File && super.equals( object ); 282// } 283 284// /** 285// * オブジェクトのハッシュコード値を返します。 286// * このメソッドは、java.io.File のハッシュ値を返すことで、equals メソッドとの整合性を取っています。 287// * 288// * @og.rev 7.2.9.4 (2020/11/20) spotbugs:equals メソッドは定義していますが hashCode メソッドは定義していないクラス 289// * @og.rev 8.0.0.0 (2021/07/31) Overriding method merely calls super 290// * 291// * @return このオブジェクトのハッシュコード値 292// */ 293// @Override 294// public int hashCode() { 295// return super.hashCode() ; // PMD:Overriding method merely calls super が出る。多分定義不要 296// } 297 298// // テスト用メソッドです 299// public static void main(String[] args) { 300// System.out.println("start"); 301// 302// FileOperation file = new FileOperationInfo("aws", "otest20190205", "sample/test.txt"); 303// 304// File parent = file.getParentFile(); 305// System.out.println(parent.getPath()); 306// System.out.println(parent.isDirectory()); 307// System.out.println(parent.isFile()); 308// 309// System.out.println("end"); 310// } 311}