Merge "Cleanup StubProvider a little."
This commit is contained in:
committed by
Android (Google) Code Review
commit
be4904962e
@@ -492,30 +492,6 @@ public class StubProvider extends DocumentsProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public File createFile(String rootId, String path, String mimeType, byte[] content)
|
||||
throws FileNotFoundException, IOException {
|
||||
Log.d(TAG, "Creating test file " + rootId + ":" + path);
|
||||
StubDocument root = mRoots.get(rootId).document;
|
||||
if (root == null) {
|
||||
throw new FileNotFoundException("No roots with the ID " + rootId + " were found");
|
||||
}
|
||||
final File file = new File(root.file, path.substring(1));
|
||||
if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
|
||||
if (!file.mkdirs()) {
|
||||
throw new FileNotFoundException("Couldn't create directory " + file.getPath());
|
||||
}
|
||||
} else {
|
||||
if (!file.createNewFile()) {
|
||||
throw new FileNotFoundException("Couldn't create file " + file.getPath());
|
||||
}
|
||||
try (final FileOutputStream fout = new FileOutputStream(file)) {
|
||||
fout.write(content);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public Uri createRegularFile(String rootId, String path, String mimeType, byte[] content)
|
||||
throws FileNotFoundException, IOException {
|
||||
@@ -560,6 +536,29 @@ public class StubProvider extends DocumentsProvider {
|
||||
return found.file;
|
||||
}
|
||||
|
||||
private File createFile(String rootId, String path, String mimeType, byte[] content)
|
||||
throws FileNotFoundException, IOException {
|
||||
Log.d(TAG, "Creating test file " + rootId + ":" + path);
|
||||
StubDocument root = mRoots.get(rootId).document;
|
||||
if (root == null) {
|
||||
throw new FileNotFoundException("No roots with the ID " + rootId + " were found");
|
||||
}
|
||||
final File file = new File(root.file, path.substring(1));
|
||||
if (DocumentsContract.Document.MIME_TYPE_DIR.equals(mimeType)) {
|
||||
if (!file.mkdirs()) {
|
||||
throw new FileNotFoundException("Couldn't create directory " + file.getPath());
|
||||
}
|
||||
} else {
|
||||
if (!file.createNewFile()) {
|
||||
throw new FileNotFoundException("Couldn't create file " + file.getPath());
|
||||
}
|
||||
try (final FileOutputStream fout = new FileOutputStream(file)) {
|
||||
fout.write(content);
|
||||
}
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
final static class RootInfo {
|
||||
public final String name;
|
||||
public final StubDocument document;
|
||||
|
||||
Reference in New Issue
Block a user