Skip to content

Commit

Permalink
style(android): java code format by the ide
Browse files Browse the repository at this point in the history
  • Loading branch information
ath0mas committed Dec 24, 2023
1 parent 265a932 commit 839210a
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 53 deletions.
10 changes: 6 additions & 4 deletions src/android/ContentFilesystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.provider.DocumentsContract;
import android.provider.MediaStore;
import android.provider.OpenableColumns;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -78,14 +79,14 @@ public LocalFilesystemURL toLocalUri(Uri inputURL) {
b.appendEncodedPath(subPath);
}
Uri localUri = b.encodedQuery(inputURL.getEncodedQuery())
.encodedFragment(inputURL.getEncodedFragment())
.build();
.encodedFragment(inputURL.getEncodedFragment())
.build();
return LocalFilesystemURL.parse(localUri);
}

@Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException {
String fileName, JSONObject options, boolean directory) throws IOException, TypeMismatchException, JSONException {
throw new UnsupportedOperationException("getFile() not supported for content:. Use resolveLocalFileSystemURL instead.");
}

Expand Down Expand Up @@ -162,9 +163,10 @@ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws

@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws NoModificationAllowedException {
int offset, boolean isBinary) throws NoModificationAllowedException {
throw new NoModificationAllowedException("Couldn't write to file given its content URI");
}

@Override
public long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
throws NoModificationAllowedException {
Expand Down
22 changes: 11 additions & 11 deletions src/android/DirectoryManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Licensed to the Apache Software Foundation (ASF) under one
/**
* This class provides file directory utilities.
* All file operations are performed on the SD card.
*
* <p>
* It is used by the FileUtils class.
*/
public class DirectoryManager {
Expand All @@ -36,8 +36,9 @@ public class DirectoryManager {

/**
* Determine if a file or directory exists.
* @param name The name of the file to check.
* @return T=exists, F=not found
*
* @param name The name of the file to check.
* @return T=exists, F=not found
*/
public static boolean testFileExists(String name) {
boolean status;
Expand All @@ -58,7 +59,7 @@ public static boolean testFileExists(String name) {
/**
* Get the free space in external storage
*
* @return Size in KB or -1 if not available
* @return Size in KB or -1 if not available
*/
public static long getFreeExternalStorageSpace() {
String status = Environment.getExternalStorageState();
Expand Down Expand Up @@ -96,7 +97,7 @@ public static long getFreeSpaceInBytes(String path) {
/**
* Determine if SD card exists.
*
* @return T=exists, F=not found
* @return T=exists, F=not found
*/
public static boolean testSaveLocationExists() {
String sDCardStatus = Environment.getExternalStorageState();
Expand All @@ -117,16 +118,15 @@ public static boolean testSaveLocationExists() {
/**
* Create a new file object from two file paths.
*
* @param file1 Base file path
* @param file2 Remaining file path
* @return File object
* @param file1 Base file path
* @param file2 Remaining file path
* @return File object
*/
private static File constructFilePaths (String file1, String file2) {
private static File constructFilePaths(String file1, String file2) {
File newPath;
if (file2.startsWith(file1)) {
newPath = new File(file2);
}
else {
} else {
newPath = new File(file1 + "/" + file2);
}
return newPath;
Expand Down
6 changes: 1 addition & 5 deletions src/android/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private void getWritePermission(String rawArgs, int action, CallbackContext call
* If your app targets Android 13 (SDK 33) or higher and needs to access media files that other apps have created,
* you must request one or more of the following granular media permissions READ_MEDIA_*
* instead of the READ_EXTERNAL_STORAGE permission:
*
* <p>
* Refer to: https://developer.android.com/about/versions/13/behavior-changes-13
*
* @return
Expand Down Expand Up @@ -659,7 +659,6 @@ public LocalFilesystemURL filesystemURLforLocalPath(String localPath) {
return localURL;
}


/* helper to execute functions async and handle the result codes
*
*/
Expand Down Expand Up @@ -834,7 +833,6 @@ private boolean removeRecursively(String baseURLstr) throws FileExistsException,
}
}


/**
* Deletes a file or directory. It is an error to attempt to delete a directory that is not empty.
* It is an error to attempt to delete the root directory of a filesystem.
Expand Down Expand Up @@ -1123,7 +1121,6 @@ public void handleData(InputStream inputStream, String contentType) {
}
}


/**
* Write contents of file.
*
Expand Down Expand Up @@ -1168,7 +1165,6 @@ private long truncateFile(String srcURLstr, long size) throws FileNotFoundExcept
}
}


/*
* Handle the response
*/
Expand Down
24 changes: 14 additions & 10 deletions src/android/Filesystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public JSONObject makeEntryForFile(File file) {
}

abstract JSONObject getFileForLocalURL(LocalFilesystemURL inputURL, String path,
JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;
JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException;

abstract boolean removeFileAtLocalURL(LocalFilesystemURL inputURL) throws InvalidModificationException, NoModificationAllowedException;

Expand Down Expand Up @@ -174,13 +174,13 @@ protected static String normalizePath(String rawPath) {
if (components.get(index).equals("..")) {
components.remove(index);
if (index > 0) {
components.remove(index-1);
components.remove(index - 1);
--index;
}
}
}
StringBuilder normalizedPath = new StringBuilder();
for(String component: components) {
for (String component : components) {
normalizedPath.append("/");
normalizedPath.append(component);
}
Expand All @@ -200,6 +200,7 @@ public long getFreeSpaceInBytes() {
}

public abstract Uri toNativeUri(LocalFilesystemURL inputURL);

public abstract LocalFilesystemURL toLocalUri(Uri inputURL);

public JSONObject getRootEntry() {
Expand All @@ -221,7 +222,7 @@ public JSONObject getParentForLocalURL(LocalFilesystemURL inputURL) throws IOExc
protected LocalFilesystemURL makeDestinationURL(String newName, LocalFilesystemURL srcURL, LocalFilesystemURL destURL, boolean isDirectory) {
// I know this looks weird but it is to work around a JSON bug.
if ("null".equals(newName) || "".equals(newName)) {
newName = srcURL.uri.getLastPathSegment();;
newName = srcURL.uri.getLastPathSegment();
}

String newDest = destURL.uri.toString();
Expand All @@ -242,7 +243,7 @@ protected LocalFilesystemURL makeDestinationURL(String newName, LocalFilesystemU
* or remove the source file when finished.
*/
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
// First, check to see that we can do it
if (move && !srcFs.canRemoveFileAtLocalURL(srcURL)) {
throw new NoModificationAllowedException("Cannot move file at source URL");
Expand Down Expand Up @@ -294,7 +295,7 @@ public void readFileAtURL(LocalFilesystemURL inputURL, long start, long end,
}

abstract long writeToFileAtURL(LocalFilesystemURL inputURL, String data, int offset,
boolean isBinary) throws NoModificationAllowedException, IOException;
boolean isBinary) throws NoModificationAllowedException, IOException;

abstract long truncateFileAtURL(LocalFilesystemURL inputURL, long size)
throws IOException, NoModificationAllowedException;
Expand All @@ -308,10 +309,12 @@ abstract long truncateFileAtURL(LocalFilesystemURL inputURL, long size)

protected class LimitedInputStream extends FilterInputStream {
long numBytesToRead;

public LimitedInputStream(InputStream in, long numBytesToRead) {
super(in);
this.numBytesToRead = numBytesToRead;
}

@Override
public int read() throws IOException {
if (numBytesToRead <= 0) {
Expand All @@ -320,14 +323,15 @@ public int read() throws IOException {
numBytesToRead--;
return in.read();
}

@Override
public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
if (numBytesToRead <= 0) {
return -1;
}
int bytesToRead = byteCount;
if (byteCount > numBytesToRead) {
bytesToRead = (int)numBytesToRead; // Cast okay; long is less than int here.
bytesToRead = (int) numBytesToRead; // Cast okay; long is less than int here.
}
int numBytesRead = in.read(buffer, byteOffset, bytesToRead);
numBytesToRead -= numBytesRead;
Expand All @@ -341,8 +345,8 @@ protected Uri.Builder createLocalUriBuilder() {
String path = LocalFilesystemURL.fsNameToCdvKeyword(name);

return new Uri.Builder()
.scheme(scheme)
.authority(hostname)
.path(path);
.scheme(scheme)
.authority(hostname)
.path(path);
}
}
20 changes: 8 additions & 12 deletions src/android/LocalFilesystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public LocalFilesystemURL URLforFilesystemPath(String path) {

@Override
public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
String path, JSONObject options, boolean directory) throws FileExistsException, IOException, TypeMismatchException, EncodingException, JSONException {
boolean create = false;
boolean exclusive = false;

Expand Down Expand Up @@ -148,8 +148,7 @@ public JSONObject getFileForLocalURL(LocalFilesystemURL inputURL,
if (!fp.exists()) {
throw new FileExistsException("create fails");
}
}
else {
} else {
if (!fp.exists()) {
throw new FileNotFoundException("path does not exist");
}
Expand Down Expand Up @@ -324,7 +323,7 @@ private void copyDirectory(Filesystem srcFs, LocalFilesystemURL srcURL, File dst

@Override
public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {
Filesystem srcFs, LocalFilesystemURL srcURL, boolean move) throws IOException, InvalidModificationException, JSONException, NoModificationAllowedException, FileExistsException {

// Check to see if the destination directory exists
String newParent = this.filesystemPathForURL(destURL);
Expand Down Expand Up @@ -371,7 +370,7 @@ public JSONObject copyFileToURL(LocalFilesystemURL destURL, String newName,

@Override
public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {
int offset, boolean isBinary) throws IOException, NoModificationAllowedException {

boolean append = false;
if (offset > 0) {
Expand All @@ -386,8 +385,7 @@ public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
rawData = data.getBytes(Charset.defaultCharset());
}
ByteArrayInputStream in = new ByteArrayInputStream(rawData);
try
{
try {
byte buff[] = new byte[rawData.length];
String absolutePath = filesystemPathForURL(inputURL);
FileOutputStream out = new FileOutputStream(absolutePath, append);
Expand All @@ -402,9 +400,7 @@ public long writeToFileAtURL(LocalFilesystemURL inputURL, String data,
if (isPublicDirectory(absolutePath)) {
broadcastNewFile(Uri.fromFile(new File(absolutePath)));
}
}
catch (NullPointerException e)
{
} catch (NullPointerException e) {
// This is a bug in the Android implementation of the Java Stack
NoModificationAllowedException realException = new NoModificationAllowedException(inputURL.toString());
realException.initCause(e);
Expand All @@ -419,7 +415,7 @@ private boolean isPublicDirectory(String absolutePath) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Lollipop has a bug where SD cards are null.
for (File f : context.getExternalMediaDirs()) {
if(f != null && absolutePath.startsWith(f.getAbsolutePath())) {
if (f != null && absolutePath.startsWith(f.getAbsolutePath())) {
return true;
}
}
Expand All @@ -429,7 +425,7 @@ private boolean isPublicDirectory(String absolutePath) {
return absolutePath.startsWith(extPath);
}

/**
/**
* Send broadcast of new file so files appear over MTP
*/
private void broadcastNewFile(Uri nativeUri) {
Expand Down
6 changes: 4 additions & 2 deletions src/android/LocalFilesystemURL.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private LocalFilesystemURL(Uri uri, String fsName, String fsPath, boolean isDire
}

public static LocalFilesystemURL parse(Uri uri) {
if(!uri.toString().contains(CDVFILE_KEYWORD)) {
if (!uri.toString().contains(CDVFILE_KEYWORD)) {
return null;
}

Expand Down Expand Up @@ -66,7 +66,9 @@ public static LocalFilesystemURL parse(String uri) {
return parse(Uri.parse(uri));
}

public static String fsNameToCdvKeyword(String fsName) { return CDVFILE_KEYWORD + fsName + "__"; }
public static String fsNameToCdvKeyword(String fsName) {
return CDVFILE_KEYWORD + fsName + "__";
}

public String toString() {
return uri.toString();
Expand Down
19 changes: 10 additions & 9 deletions src/android/PendingRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,23 @@ class PendingRequests {
/**
* Creates a request and adds it to the array of pending requests. Each created request gets a
* unique result code for use with requestPermission()
* @param rawArgs The raw arguments passed to the plugin
* @param action The action this request corresponds to (get file, etc.)
* @param callbackContext The CallbackContext for this plugin call
* @return The request code that can be used to retrieve the Request object
*
* @param rawArgs The raw arguments passed to the plugin
* @param action The action this request corresponds to (get file, etc.)
* @param callbackContext The CallbackContext for this plugin call
* @return The request code that can be used to retrieve the Request object
*/
public synchronized int createRequest(String rawArgs, int action, CallbackContext callbackContext) {
public synchronized int createRequest(String rawArgs, int action, CallbackContext callbackContext) {
Request req = new Request(rawArgs, action, callbackContext);
requests.put(req.requestCode, req);
return req.requestCode;
}

/**
* Gets the request corresponding to this request code and removes it from the pending requests
* @param requestCode The request code for the desired request
* @return The request corresponding to the given request code or null if such a
* request is not found
*
* @param requestCode The request code for the desired request
* @return The request corresponding to the given request code or null if such a request is not found
*/
public synchronized Request getAndRemove(int requestCode) {
Request result = requests.get(requestCode);
Expand Down Expand Up @@ -76,7 +77,7 @@ private Request(String rawArgs, int action, CallbackContext callbackContext) {
this.rawArgs = rawArgs;
this.action = action;
this.callbackContext = callbackContext;
this.requestCode = currentReqId ++;
this.requestCode = currentReqId++;
}

public int getAction() {
Expand Down

0 comments on commit 839210a

Please sign in to comment.