3333import java .io .File ;
3434import java .util .ArrayList ;
3535import java .util .Collections ;
36- import java .util .Comparator ;
3736import java .util .List ;
3837import java .util .Locale ;
3938import java .util .concurrent .ExecutorService ;
@@ -54,11 +53,12 @@ public class HostFileProfile extends FileProfile {
5453 */
5554 private String ATTRIBUTE_DIRECTORY = "directory" ;
5655
57- /** FileManager. */
58- private FileManager mFileManager ;
59-
6056 private ExecutorService mImageService = Executors .newSingleThreadExecutor ();
6157
58+ private File getBasePath () {
59+ return getFileManager ().getBasePath ();
60+ }
61+
6262 private final DConnectApi mGetReceiveApi = new GetApi () {
6363
6464 @ Override
@@ -70,10 +70,10 @@ public boolean onRequest(final Intent request, final Intent response) {
7070
7171 // パス名の先頭に"/"が含まれている場合
7272 if (path .indexOf ("/" ) == 0 ) {
73- mFile = new File (getFileManager (). getBasePath () + path );
73+ mFile = new File (getBasePath () + path );
7474 filePath = getFileManager ().getContentUri () + path ;
7575 } else {
76- mFile = new File (getFileManager (). getBasePath () + "/" + path );
76+ mFile = new File (getBasePath () + "/" + path );
7777 filePath = getFileManager ().getContentUri () + "/" + path ;
7878 }
7979
@@ -104,16 +104,16 @@ public boolean onRequest(final Intent request, final Intent response) {
104104 }
105105 // パス名の先頭に"/"が含まれている場合
106106 if (oldPath .indexOf ("/" ) == 0 ) {
107- oldFile = new File (getFileManager (). getBasePath () + oldPath );
107+ oldFile = new File (getBasePath () + oldPath );
108108 oldFilePath [0 ] = getFileManager ().getContentUri () + "/" + oldFile .getName ();
109109 } else {
110- oldFile = new File (getFileManager (). getBasePath () + "/" + oldPath );
110+ oldFile = new File (getBasePath () + "/" + oldPath );
111111 oldFilePath [0 ] = getFileManager ().getContentUri () + "/" + oldFile .getName ();
112112 }
113113 if (newPath .indexOf ("/" ) == 0 ) {
114- newFile = new File (getFileManager (). getBasePath () + newPath );
114+ newFile = new File (getBasePath () + newPath );
115115 } else {
116- newFile = new File (getFileManager (). getBasePath () + "/" + newPath );
116+ newFile = new File (getBasePath () + "/" + newPath );
117117 }
118118 File newDirectory = new File (newFile .getParent ());
119119 if (!newDirectory .exists ()) {
@@ -254,7 +254,7 @@ public boolean onRequest(final Intent request, final Intent response) {
254254 getFileManager ().checkWritePermission (new FileManager .CheckPermissionCallback () {
255255 @ Override
256256 public void onSuccess () {
257- File mBaseDir = mFileManager . getBasePath ();
257+ File mBaseDir = getBasePath ();
258258 File mMakeDir = new File (mBaseDir , path );
259259
260260 if (mMakeDir .isDirectory ()) {
@@ -297,7 +297,7 @@ public boolean onRequest(final Intent request, final Intent response) {
297297 public void onSuccess () {
298298 String oldPath = request .getStringExtra ("oldPath" );
299299 String newPath = request .getStringExtra ("newPath" );
300- File baseDir = mFileManager . getBasePath ();
300+ File baseDir = getBasePath ();
301301 File oldDir = new File (baseDir , oldPath );
302302 File newDir = new File (baseDir , newPath );
303303 File tempNewDir = new File (baseDir , newPath + "/" + oldDir .getName ());
@@ -364,7 +364,7 @@ public boolean onRequest(final Intent request, final Intent response) {
364364 getFileManager ().checkWritePermission (new FileManager .CheckPermissionCallback () {
365365 @ Override
366366 public void onSuccess () {
367- File mBaseDir = mFileManager . getBasePath ();
367+ File mBaseDir = getBasePath ();
368368 File mDeleteDir = new File (mBaseDir , path );
369369
370370 if (mDeleteDir .isFile ()) {
@@ -414,11 +414,11 @@ private void getFileList(final Intent request, final Intent response) {
414414 Boolean currentTop = false ;
415415 if (path == null ) {
416416 // nullの時はTopに指定
417- tmpDir = getFileManager (). getBasePath ();
417+ tmpDir = getBasePath ();
418418 currentTop = true ;
419419 } else if (path .equals ("/" )) {
420420 // /の場合はTopに指定
421- tmpDir = getFileManager (). getBasePath ();
421+ tmpDir = getBasePath ();
422422 currentTop = true ;
423423 } else if (path .contains (".." )) {
424424 // ..の場合は、1つ上のフォルダを指定
@@ -434,10 +434,10 @@ private void getFileList(final Intent request, final Intent response) {
434434 if (mDirs .length == 1 || mPath .equals ("/" )) {
435435 currentTop = true ;
436436 }
437- tmpDir = new File (getFileManager (). getBasePath (), mPath );
437+ tmpDir = new File (getBasePath (), mPath );
438438 } else {
439439 // それ以外は、そのフォルダを指定
440- tmpDir = new File (getFileManager (). getBasePath () + "/" + path );
440+ tmpDir = new File (getBasePath () + "/" + path );
441441 currentTop = false ;
442442 }
443443
@@ -474,7 +474,7 @@ public void onSuccess() {
474474 tmpPath = finalMPath ;
475475 }
476476 File parentDir = new File (tmpPath + "/.." );
477- String path = parentDir .getPath ().replaceAll ("" + mFileManager . getBasePath (), "" );
477+ String path = parentDir .getPath ().replaceAll ("" + getBasePath (), "" );
478478 String name = parentDir .getName ();
479479 Long size = parentDir .length ();
480480 String mineType = "folder/dir" ;
@@ -568,7 +568,7 @@ private void saveFile(final Intent response, final String path, final String mim
568568 public void onSuccess (@ NonNull final String uri ) {
569569 String mMineType = mimeType ;
570570 if (mMineType == null ) {
571- mMineType = getMIMEType (getFileManager (). getBasePath () + "/" + path );
571+ mMineType = getMIMEType (getBasePath () + "/" + path );
572572 }
573573
574574 if (BuildConfig .DEBUG ) {
@@ -588,7 +588,7 @@ public void onSuccess(@NonNull final String uri) {
588588 || mMineType .endsWith ("audio/mp3" ) || mMineType .endsWith ("audio/x-ms-wma" )) {
589589
590590 MediaMetadataRetriever mMediaMeta = new MediaMetadataRetriever ();
591- mMediaMeta .setDataSource (getFileManager (). getBasePath () + "/" + path );
591+ mMediaMeta .setDataSource (getBasePath () + "/" + path );
592592 String mTitle = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_TITLE );
593593 String mComposer = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_COMPOSER );
594594 String mArtist = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_ARTIST );
@@ -606,13 +606,13 @@ public void onSuccess(@NonNull final String uri) {
606606 mValues .put (MediaStore .Audio .Media .ARTIST , mArtist );
607607 mValues .put (MediaStore .Audio .Media .DURATION , mDuration );
608608 mValues .put (MediaStore .Audio .Media .MIME_TYPE , mMineType );
609- mValues .put (MediaStore .Audio .Media .DATA , getFileManager (). getBasePath () + "/" + path );
609+ mValues .put (MediaStore .Audio .Media .DATA , getBasePath () + "/" + path );
610610 mContentResolver .insert (MediaStore .Audio .Media .EXTERNAL_CONTENT_URI , mValues );
611611 } else if (mMineType .endsWith ("video/mp4" ) || mMineType .endsWith ("video/3gpp" )
612612 || mMineType .endsWith ("video/3gpp2" ) || mMineType .endsWith ("video/mpeg" )
613613 || mMineType .endsWith ("video/m4v" )) {
614614 MediaMetadataRetriever mMediaMeta = new MediaMetadataRetriever ();
615- mMediaMeta .setDataSource (getFileManager (). getBasePath () + "/" + path );
615+ mMediaMeta .setDataSource (getBasePath () + "/" + path );
616616 String mTitle = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_TITLE );
617617 String mArtist = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_ARTIST );
618618 String mDuration = mMediaMeta .extractMetadata (MediaMetadataRetriever .METADATA_KEY_DURATION );
@@ -624,7 +624,7 @@ public void onSuccess(@NonNull final String uri) {
624624 mValues .put (MediaStore .Video .Media .ARTIST , mArtist );
625625 mValues .put (MediaStore .Video .Media .DURATION , mDuration );
626626 mValues .put (MediaStore .Video .Media .MIME_TYPE , mMineType );
627- mValues .put (MediaStore .Video .Media .DATA , getFileManager (). getBasePath () + "/" + path );
627+ mValues .put (MediaStore .Video .Media .DATA , getBasePath () + "/" + path );
628628 mContentResolver .insert (MediaStore .Video .Media .EXTERNAL_CONTENT_URI , mValues );
629629 }
630630 setResult (response , DConnectMessage .RESULT_OK );
@@ -696,7 +696,6 @@ private boolean isForce(final Intent request, final String key) {
696696 */
697697 public HostFileProfile (final FileManager fileMgr ) {
698698 super (fileMgr );
699- mFileManager = fileMgr ;
700699 addApi (mGetReceiveApi );
701700 addApi (mPutMoveApi );
702701 addApi (mGetListApi );
@@ -743,7 +742,7 @@ protected ArrayList<FileAttribute> sortFilelist(final String order, final ArrayL
743742 */
744743 protected ArrayList <FileAttribute > setArrayList (final File [] respFileList , final ArrayList <FileAttribute > filelist ) {
745744 for (File file : respFileList ) {
746- String path = file .getPath ().replaceAll ("" + mFileManager . getBasePath (), "" );
745+ String path = file .getPath ().replaceAll ("" + getBasePath (), "" );
747746 if (path == null ) {
748747 path = "unknown" ;
749748 }
0 commit comments