Skip to content

Commit

Permalink
Merge pull request #4032 from pingwang2011/timob-12901
Browse files Browse the repository at this point in the history
timob-12901: Android: Ti.FileSystemProxy interprets resourceDir as a File
  • Loading branch information
ayeung committed Mar 26, 2013
2 parents a783f7c + 8de1add commit d8fe990
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,36 @@ public class TiResourceFile extends TiBaseFile
private static final String TAG = "TiResourceFile";

private final String path;
private boolean typeFetched = false;

public TiResourceFile(String path)
{
super(TYPE_RESOURCE);
this.path = path;
}

@Override
public boolean isDirectory()
{
if (typeFetched) {
return this.typeDir;
}

fetchType();
return this.typeDir;
}

@Override
public boolean isFile()
{
if (typeFetched) {
return this.typeFile;
}

fetchType();
return this.typeFile;
}

@Override
public TiBaseFile resolve()
{
Expand Down Expand Up @@ -243,4 +266,27 @@ public String toString ()
{
return toURL();
}

private void fetchType ()
{
InputStream is = null;
try {
is = getInputStream();
this.typeDir = false;
this.typeFile = true;
} catch (IOException e) {
// getInputStream() will throw a FileNotFoundException if it is a directory or it does not exist.
this.typeDir = true;
this.typeFile = false;
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
typeFetched = true;
}
}

0 comments on commit d8fe990

Please sign in to comment.