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 org.opengion.fukurou.model.FileOperation;
020// import org.opengion.fukurou.model.CloudFileOperation;                // 8.0.0.2 (2021/10/15) fukurou.model → plugin.cloud にパッケージ移動
021import org.opengion.fukurou.model.FileOperationFactory;
022
023import java.io.File;
024import java.io.FileFilter;
025import java.io.FileNotFoundException;
026import java.io.IOException;
027import java.io.InputStream;
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.0.0.1 (2021/10/08)" ;
046        private static final long serialVersionUID = 800120211008L ;
047
048        /** クラス変数 */
049        private final String plugin;
050
051        private long size;
052        // 8.0.0.0 (2021/07/31) Field ** has the same name as a method
053//      private long lastModified;
054//      private boolean isFile;
055//      private boolean isDirectory;
056        private long lastTime;                          // 最終時刻
057        private boolean isFil;                          // ファイルか?
058        private boolean isDir;                          // フォルダか?
059        private FileOperation file;                     // ファイルオペレータ
060
061        /**
062         * コンストラクタ
063         *
064         * 生成時の初期処理。
065         *
066         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
067         *
068         * @param plugin プラグイン名
069         * @param bucket バケット名
070         * @param path ファイルパス
071         */
072        public FileOperationInfo(final String plugin, final String bucket, final String path) {
073                super(bucket, path);
074                this.plugin     = plugin;
075                size            = 0;
076//              lastModified = 0;
077//              isFile = false;
078//              isDirectory = false;
079                lastTime        = 0L;
080                isFil           = false;
081                isDir           = false;
082                file            = null;
083        }
084
085        /**
086         * FileOperationクラスの遅延生成
087         *
088         * 呼び出し時に、FileOperationインスタンスが未生成の場合は、
089         * 生成を行います。
090         */
091        private void setFileOperation() {
092                if(file == null) {
093                        file = FileOperationFactory.newStorageOperation( plugin, conBucket, conPath );
094                }
095        }
096
097        /** Method */
098
099        /**
100         * 書き込み処理(評価用)
101         *
102         * Fileを書き込みます。
103         *
104         * @og.rev 8.0.0.1 (2021/10/08) 新規追加
105         *
106         * @param inFile 書き込みFile
107         * @throws IOException ファイル関連エラー情報
108         */
109        @Override
110        public void write(final File inFile) throws IOException {
111                setFileOperation();
112                file.write(inFile);
113        }
114
115        /**
116         * 書き込み処理
117         *
118         * InputStreamのデータを書き込みます。
119         *
120         * @param is 書き込みデータのInputStream
121         * @throws IOException ファイル関連エラー情報
122         */
123        @Override
124        public void write(final InputStream is) throws IOException {
125                setFileOperation();
126                file.write(is);
127        }
128
129        /**
130         * 読み込み処理
131         *
132         * データを読み込み、InputStreamとして、返します。
133         *
134         * @return 読み込みデータのInputStream
135         * @throws FileNotFoundException ファイル非存在エラー情報
136         */
137        @Override
138        public InputStream read() throws FileNotFoundException {
139                setFileOperation();
140                return file.read();
141        }
142
143        /**
144         * 削除処理
145         *
146         * ファイルを削除します。
147         *
148         * @return 成否フラグ
149         */
150        @Override
151        public boolean delete() {
152                setFileOperation();
153                return file.delete();
154        }
155
156        /**
157         * コピー処理
158         *
159         * ファイルを指定先に、コピーします。
160         *
161         * @param afPath コピー先
162         * @return 成否フラグ
163         */
164        @Override
165        public boolean copy(final String afPath) {
166                setFileOperation();
167                return file.copy(afPath);
168        }
169
170        /**
171         * 一覧取得(Fileクラス)
172         *
173         * この抽象パス名が示すディレクトリ内のファイルを示す抽象パス名の配列を返します。
174         * 1つ下の、ディレクトリ・ファイル一覧を取得します。
175         *
176         * @param filter フィルタ情報
177         * @return ファイル一覧
178         * @see java.io.File#listFiles(FileFilter)
179         */
180        @Override
181        public File[] listFiles(final FileFilter filter) {
182                setFileOperation();
183                return file.listFiles(filter);
184        }
185
186        /**
187         * ファイルサイズ取得(Fileクラス)
188         *
189         * ファイルサイズを取得します。
190         *
191         * @return ファイルサイズ
192         * @see java.io.File#length()
193         */
194        @Override
195        public long length() {
196                return size;
197        }
198
199        /**
200         * ファイルサイズ設定
201         *
202         * ファイルサイズを設定します。
203         *
204         * @param size ファイルサイズ
205         */
206        protected void setSize(final long size) {
207                this.size = size;
208        }
209
210        /**
211         * 最終更新時刻の取得(Fileクラス)
212         *
213         * 最終更新時刻を取得します。
214         *
215         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
216         *
217         * @return 最終更新時刻
218         * @see java.io.File#lastModified()
219         */
220        @Override
221        public long lastModified() {
222//              return lastModified;
223                return lastTime;
224        }
225
226        /**
227         * 最終更新時刻の設定
228         *
229         * 最終更新時刻を設定します。
230         *
231         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
232         *
233         * @param lastModified 最終更新時刻
234         */
235        protected void setLastModifiedValue(final long lastModified) {
236//              this.lastModified = lastModified;
237                lastTime = lastModified;
238        }
239
240        /**
241         * ファイル判定取得(Fileクラス)
242         *
243         * ファイルであるかの判定を返します。
244         *
245         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
246         *
247         * @return ファイル判定
248         * @see java.io.File#isFile()
249         */
250        @Override
251        public boolean isFile() {
252//              return isFile;
253                return isFil;
254        }
255
256        /**
257         * ファイル判定設定
258         *
259         * ファイルであるかの判定を設定します。
260         *
261         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
262         *
263         * @param isFile ファイル判定
264         */
265        protected void setFile(final boolean isFile) {
266//              this.isFile = isFile;
267                isFil = isFile;
268        }
269
270        /**
271         * ディレクトリ判定取得(Fileクラス)
272         *
273         * ディレクトリであるかの判定を返します。
274         *
275         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
276         *
277         * @return ディレクトリ判定
278         * @see java.io.File#isDirectory()
279         */
280        @Override
281        public boolean isDirectory() {
282//              return isDirectory;
283                return isDir;
284        }
285
286        /**
287         * ディレクトリ判定設定
288         *
289         * ディレクトリであるかの判定を設定します。
290         *
291         * @og.rev 8.0.0.0 (2021/07/31) Field ** has the same name as a method
292         *
293         * @param isDirectory ディレクトリ判定
294         */
295        protected void setDirectory(final boolean isDirectory) {
296//              this.isDirectory = isDirectory;
297                isDir = isDirectory;
298        }
299
300        /**
301         * 親情報の取得(Fileクラス)
302         *
303         * 親情報を返します。
304         *
305         * @return 親情報
306         * @see java.io.File#getParentFile()
307         */
308        @Override
309        public File getParentFile() {
310//              return  FileOperationFactory.newStorageOperation( file , this.getParent() );
311                return  FileOperationFactory.resolveFile( file , this.getParent() );
312        }
313}