001/* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016// package org.opengion.fukurou.model; 017package org.opengion.cloud; 018 019import java.io.File; 020import java.io.FileFilter; 021import java.io.FileNotFoundException; 022import java.io.IOException; 023import java.io.InputStream; 024 025import org.opengion.fukurou.system.FileOperation; // 8.5.6.0 (2024/02/29) package変更 fukurou.model → fukurou.system 026// import org.opengion.fukurou.model.CloudFileOperation; // 8.0.0.2 (2021/10/15) fukurou.model → plugin.cloud ã«ãƒ‘ッケージ移動 027import org.opengion.fukurou.system.FileOperationFactory; // 8.5.6.0 (2024/02/29) package変更 fukurou.model → fukurou.system 028 029/** 030 * CloudFileOperation用ã®ãƒ•ã‚¡ã‚¤ãƒ«æƒ…å ±ã®æ ¼ç´ã‚¯ãƒ©ã‚¹ 031 * 032 * listFilesã§å–å¾—ã—ãŸã€ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªã¨ãƒ•ã‚¡ã‚¤ãƒ«ä¸€è¦§æƒ…å ±ã‚’æ ¼ç´ã—ã¾ã™ã€‚ 033 * 034 * パフォーマンスや分ã‹ã‚Šã‚„ã™ã•ã‚’考慮ã—ã¦CloudFileOperationã‹ã‚‰ã¯åˆ†é›¢ã—ã¦ã„ã¾ã™ 035 * 036 * @og.group ファイルæ“作 037 * 038 * @og.rev 5.10.8.0 (2019/02/01) æ–°è¦ä½œæˆ 039 * @og.rev 5.10.9.0 (2019/03/01) 変更対応 040 * @author oota 041 * @since JDK7.0 042 */ 043public class FileOperationInfo extends CloudFileOperation { 044 /** ã“ã®ãƒ—ãƒã‚°ãƒ©ãƒ ã®VERSIONæ–‡å—列をè¨å®šã—ã¾ã™ã€‚{@value} */ 045 private static final String VERSION = "8.5.4.2 (2024/01/12)" ; 046 private static final long serialVersionUID = 854220240112L ; 047 048 /** クラス変数 */ 049 private final String plugin; 050 051 /** ファイルサイズå–å¾—(Fileクラス) */ 052 private long size; 053 // 8.0.0.0 (2021/07/31) Field ** has the same name as a method 054// private long lastModified; 055// private boolean isFile; 056// private boolean isDirectory; 057 /** 最終時刻 */ 058 private long lastTime; 059 /** ファイルã‹ã©ã†ã‹ */ 060 private boolean isFil; 061 /** フォルダã‹ã©ã†ã‹ */ 062 private boolean isDir; 063 /** ファイルオペレータ(クラウド系ファイルオブジェクト) */ 064 private FileOperation file; 065 066 /** 067 * コンストラクタ 068 * 069 * 生æˆæ™‚ã®åˆæœŸå‡¦ç†ã€‚ 070 * 071 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 072 * 073 * @param plugin プラグインå 074 * @param bucket ãƒã‚±ãƒƒãƒˆå 075 * @param path ファイルパス 076 */ 077 public FileOperationInfo(final String plugin, final String bucket, final String path) { 078 super(bucket, path); 079 this.plugin = plugin; 080 size = 0; 081// lastModified = 0; 082// isFile = false; 083// isDirectory = false; 084 lastTime = 0L; 085 isFil = false; 086 isDir = false; 087 file = null; 088 } 089 090 /** 091 * FileOperationクラスã®é…å»¶ç”Ÿæˆ 092 * 093 * 呼ã³å‡ºã—時ã«ã€FileOperationインスタンスãŒæœªç”Ÿæˆã®å ´åˆã¯ã€ 094 * 生æˆã‚’è¡Œã„ã¾ã™ã€‚ 095 */ 096 private void setFileOperation() { 097 if(file == null) { 098 file = FileOperationFactory.newStorageOperation( plugin, conBucket, conPath ); 099 } 100 } 101 102 /** Method */ 103 104 /** 105 * 書ãè¾¼ã¿å‡¦ç†(評価用) 106 * 107 * Fileを書ãè¾¼ã¿ã¾ã™ã€‚ 108 * 109 * @og.rev 8.0.0.1 (2021/10/08) æ–°è¦è¿½åŠ 110 * 111 * @param inFile 書ãè¾¼ã¿File 112 * @throws IOException ãƒ•ã‚¡ã‚¤ãƒ«é–¢é€£ã‚¨ãƒ©ãƒ¼æƒ…å ± 113 */ 114 @Override // FileOperation 115 public void write(final File inFile) throws IOException { 116 setFileOperation(); 117 file.write(inFile); 118 } 119 120 /** 121 * 書ãè¾¼ã¿å‡¦ç† 122 * 123 * InputStreamã®ãƒ‡ãƒ¼ã‚¿ã‚’書ãè¾¼ã¿ã¾ã™ã€‚ 124 * 125 * @param is 書ãè¾¼ã¿ãƒ‡ãƒ¼ã‚¿ã®InputStream 126 * @throws IOException ãƒ•ã‚¡ã‚¤ãƒ«é–¢é€£ã‚¨ãƒ©ãƒ¼æƒ…å ± 127 */ 128 @Override // FileOperation 129 public void write(final InputStream is) throws IOException { 130 setFileOperation(); 131 file.write(is); 132 } 133 134 /** 135 * èªã¿è¾¼ã¿å‡¦ç† 136 * 137 * データをèªã¿è¾¼ã¿ã€InputStreamã¨ã—ã¦ã€è¿”ã—ã¾ã™ã€‚ 138 * 139 * @og.rev 8.5.4.2 (2024/01/12) throws ã‚’ FileNotFoundException ⇒ IOException ã«å¤‰æ›´ 140 * 141 * @return èªã¿è¾¼ã¿ãƒ‡ãƒ¼ã‚¿ã®InputStream 142 * @throws FileNotFoundException ファイルéžå˜åœ¨ã‚¨ãƒ©ãƒ¼æƒ…å ± 143 */ 144 @Override // FileOperation 145// public InputStream read() throws FileNotFoundException { 146 public InputStream read() throws IOException { 147 setFileOperation(); 148 return file.read(); 149 } 150 151 /** 152 * å‰Šé™¤å‡¦ç† 153 * 154 * ファイルを削除ã—ã¾ã™ã€‚ 155 * 156 * @return æˆå¦ãƒ•ãƒ©ã‚° 157 */ 158 @Override // File 159 public boolean delete() { 160 setFileOperation(); 161 return file.delete(); 162 } 163 164 /** 165 * ã‚³ãƒ”ãƒ¼å‡¦ç† 166 * 167 * ファイルを指定先ã«ã€ã‚³ãƒ”ーã—ã¾ã™ã€‚ 168 * 169 * @param afPath コピー先 170 * @return æˆå¦ãƒ•ãƒ©ã‚° 171 */ 172 @Override // FileOperation 173 public boolean copy(final String afPath) { 174 setFileOperation(); 175 return file.copy(afPath); 176 } 177 178 /** 179 * 一覧å–å¾—(Fileクラス) 180 * 181 * ã“ã®æŠ½è±¡ãƒ‘スåãŒç¤ºã™ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªå†…ã®ãƒ•ã‚¡ã‚¤ãƒ«ã‚’示ã™æŠ½è±¡ãƒ‘スåã®é…列を返ã—ã¾ã™ã€‚ 182 * 1ã¤ä¸‹ã®ã€ãƒ‡ã‚£ãƒ¬ã‚¯ãƒˆãƒªãƒ»ãƒ•ã‚¡ã‚¤ãƒ«ä¸€è¦§ã‚’å–å¾—ã—ã¾ã™ã€‚ 183 * 184 * @param filter ãƒ•ã‚£ãƒ«ã‚¿æƒ…å ± 185 * @return ファイル一覧 186 * @see java.io.File#listFiles(FileFilter) 187 */ 188 @Override // File 189 public File[] listFiles(final FileFilter filter) { 190 setFileOperation(); 191 return file.listFiles(filter); 192 } 193 194 /** 195 * ファイルサイズå–å¾—(Fileクラス) 196 * 197 * ファイルサイズをå–å¾—ã—ã¾ã™ã€‚ 198 * 199 * @return ファイルサイズ 200 * @see java.io.File#length() 201 */ 202 @Override // File 203 public long length() { 204 return size; 205 } 206 207 /** 208 * ファイルサイズè¨å®š 209 * 210 * ファイルサイズをè¨å®šã—ã¾ã™ã€‚ 211 * 212 * @param size ファイルサイズ 213 */ 214 protected void setSize(final long size) { 215 this.size = size; 216 } 217 218 /** 219 * 最終更新時刻ã®å–å¾—(Fileクラス) 220 * 221 * 最終更新時刻をå–å¾—ã—ã¾ã™ã€‚ 222 * 223 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 224 * 225 * @return 最終更新時刻 226 * @see java.io.File#lastModified() 227 */ 228 @Override // File 229 public long lastModified() { 230// return lastModified; 231 return lastTime; 232 } 233 234 /** 235 * 最終更新時刻ã®è¨å®š 236 * 237 * 最終更新時刻をè¨å®šã—ã¾ã™ã€‚ 238 * 239 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 240 * 241 * @param lastModified 最終更新時刻 242 */ 243 protected void setLastModifiedValue(final long lastModified) { 244// this.lastModified = lastModified; 245 lastTime = lastModified; 246 } 247 248 /** 249 * ファイル判定å–å¾—(Fileクラス) 250 * 251 * ファイルã§ã‚ã‚‹ã‹ã®åˆ¤å®šã‚’è¿”ã—ã¾ã™ã€‚ 252 * 253 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 254 * 255 * @return ファイル判定 256 * @see java.io.File#isFile() 257 */ 258 @Override // File 259 public boolean isFile() { 260// return isFile; 261 return isFil; 262 } 263 264 /** 265 * ファイル判定è¨å®š 266 * 267 * ファイルã§ã‚ã‚‹ã‹ã®åˆ¤å®šã‚’è¨å®šã—ã¾ã™ã€‚ 268 * 269 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 270 * 271 * @param isFile ファイル判定 272 */ 273 protected void setFile(final boolean isFile) { 274// this.isFile = isFile; 275 isFil = isFile; 276 } 277 278 /** 279 * ディレクトリ判定å–å¾—(Fileクラス) 280 * 281 * ディレクトリã§ã‚ã‚‹ã‹ã®åˆ¤å®šã‚’è¿”ã—ã¾ã™ã€‚ 282 * 283 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 284 * 285 * @return ディレクトリ判定 286 * @see java.io.File#isDirectory() 287 */ 288 @Override // File 289 public boolean isDirectory() { 290// return isDirectory; 291 return isDir; 292 } 293 294 /** 295 * ディレクトリ判定è¨å®š 296 * 297 * ディレクトリã§ã‚ã‚‹ã‹ã®åˆ¤å®šã‚’è¨å®šã—ã¾ã™ã€‚ 298 * 299 * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method 300 * 301 * @param isDirectory ディレクトリ判定 302 */ 303 protected void setDirectory(final boolean isDirectory) { 304// this.isDirectory = isDirectory; 305 isDir = isDirectory; 306 } 307 308 /** 309 * è¦ªæƒ…å ±ã®å–å¾—(Fileクラス) 310 * 311 * è¦ªæƒ…å ±ã‚’è¿”ã—ã¾ã™ã€‚ 312 * 313 * @return è¦ªæƒ…å ± 314 * @see java.io.File#getParentFile() 315 */ 316 @Override // File 317 public File getParentFile() { 318// return FileOperationFactory.newStorageOperation( file , this.getParent() ); 319 return FileOperationFactory.resolveFile( file , this.getParent() ); 320 } 321}