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 { 025 /** クラス変数 */ 026 private String plugin; 027 private long size; 028 private long lastModified; 029 private boolean isFile; 030 private boolean isDirectory; 031 private FileOperation file; 032 033 /** 034 * コンストラクタ 035 * 036 * 生成時の初期処理。 037 * 038 * @param plugin プラグイン名 039 * @param bucket バケット名 040 * @param path ファイルパス 041 */ 042 public FileOperationInfo(String plugin, String bucket, String path) { 043 super(bucket, path); 044 this.plugin = plugin; 045 size = 0; 046 lastModified = 0; 047 isFile = false; 048 isDirectory = false; 049 file = null; 050 } 051 052 /** 053 * FileOperationクラスの生成 054 * 055 * 呼び出し時に、FileOperationインスタンスが未生成の場合は、 056 * 生成を行います。 057 */ 058 private void setFileOperation() { 059 if(file == null) { 060 file = FileOperationFactory.newStorageOperation( plugin, conBucket, conPath ); 061 } 062 } 063 064 /** Method */ 065 /** 066 * 書き込み処理 067 * 068 * InputStreamのデータを書き込みます。 069 * 070 * @param is 書き込みデータのInputStream 071 * @throws IOException ファイル関連エラー情報 072 */ 073 @Override 074 public void write(InputStream is) throws IOException { 075 setFileOperation(); 076 file.write(is); 077 } 078 079 /** 080 * 読み込み処理 081 * 082 * データを読み込み、InputStreamとして、返します。 083 * 084 * @return 読み込みデータのInputStream 085 * @throws FileNotFoundException ファイル非存在エラー情報 086 */ 087 @Override 088 public InputStream read() throws FileNotFoundException { 089 setFileOperation(); 090 return file.read(); 091 } 092 093 /** 094 * 削除処理 095 * 096 * ファイルを削除します。 097 * 098 * @return 成否フラグ 099 */ 100 @Override 101 public boolean delete() { 102 setFileOperation(); 103 return file.delete(); 104 } 105 106 /** 107 * コピー処理 108 * 109 * ファイルを指定先に、コピーします。 110 * 111 * @param afPath コピー先 112 * @return 成否フラグ 113 */ 114 @Override 115 public boolean copy(String afPath) { 116 setFileOperation(); 117 return file.copy(afPath); 118 } 119 120 /** 121 * 一覧取得 122 * 123 * 1つ下の、ディレクトリ・ファイル一覧を取得します。 124 * 125 * @param filter フィルタ情報 126 * @return ファイル一覧 127 */ 128 @Override 129 public File[] listFiles(FileFilter filter) { 130 setFileOperation(); 131 return file.listFiles(filter); 132 } 133 134 /** 135 * ファイルサイズ取得 136 * 137 * ファイルサイズを取得します。 138 * 139 * @return ファイルサイズ 140 */ 141 @Override 142 public long length() { 143 return size; 144 } 145 146 /** 147 * ファイルサイズ設定 148 * 149 * ファイルサイズを設定します。 150 * 151 * @param size ファイルサイズ 152 */ 153 public void setSize(long size) { 154 this.size = size; 155 } 156 157 /** 158 * 最終更新時刻の取得 159 * 160 * 最終更新時刻を取得します。 161 * 162 * @return 最終更新時刻 163 */ 164 @Override 165 public long lastModified() { 166 return lastModified; 167 } 168 169 /** 170 * 最終更新時刻の設定 171 * 172 * 最終更新時刻を設定します。 173 * 174 * @param lastModified 最終更新時刻 175 */ 176 public void setLastModifiedValue(long lastModified) { 177 this.lastModified = lastModified; 178 } 179 180 /** 181 * ファイル判定取得 182 * 183 * ファイルであるかの判定を返します。 184 * 185 * @return ファイル判定 186 */ 187 @Override 188 public boolean isFile() { 189 return isFile; 190 } 191 192 /** 193 * ファイル判定設定 194 * 195 * ファイルであるかの判定を設定します。 196 * 197 * @param isFile ファイル判定 198 */ 199 public void setFile(boolean isFile) { 200 this.isFile = isFile; 201 } 202 203 /** 204 * ディレクトリ判定取得 205 * 206 * ディレクトリであるかの判定を返します。 207 * 208 * @return ディレクトリ判定 209 */ 210 @Override 211 public boolean isDirectory() { 212 return isDirectory; 213 } 214 215 /** 216 * ディレクトリ判定設定 217 * 218 * ディレクトリであるかの判定を設定します。 219 * 220 * @param isDirectory ディレクトリ判定 221 */ 222 public void setDirectory(boolean isDirectory) { 223 this.isDirectory = isDirectory; 224 } 225 226 227 /** 228 * 親情報の取得 229 * 230 * 親情報を返します。 231 * 232 * @return 親情報 233 */ 234 @Override 235 public File getParentFile() { 236 return FileOperationFactory.newStorageOperation( file , this.getParent() ); 237 } 238 239// // テスト用メソッドです 240// public static void main(String[] args) { 241// System.out.println("start"); 242// 243// FileOperation file = new FileOperationInfo("aws", "otest20190205", "sample/test.txt"); 244// 245// File parent = file.getParentFile(); 246// System.out.println(parent.getPath()); 247// System.out.println(parent.isDirectory()); 248// System.out.println(parent.isFile()); 249// 250// System.out.println("end"); 251// } 252}