Browse Source

Java 7 migration

pull/559/head
TacoTheDank 4 years ago
parent
commit
c1527cb36d
  1. 7
      app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java
  2. 8
      app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java
  3. 4
      app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java
  4. 6
      app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java
  5. 2
      app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java
  6. 6
      app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java
  7. 2
      app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java
  8. 2
      app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java
  9. 2
      app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java
  10. 2
      app/src/main/java/org/transdroid/core/seedbox/SeedboxSettingsImpl.java
  11. 10
      app/src/main/java/org/transdroid/daemon/DummyAdapter.java
  12. 2
      app/src/main/java/org/transdroid/daemon/Priority.java
  13. 2
      app/src/main/java/org/transdroid/daemon/TorrentDetails.java
  14. 2
      app/src/main/java/org/transdroid/daemon/TorrentFile.java
  15. 2
      app/src/main/java/org/transdroid/daemon/TorrentFilesSortBy.java
  16. 2
      app/src/main/java/org/transdroid/daemon/TorrentStatus.java
  17. 2
      app/src/main/java/org/transdroid/daemon/TorrentsSortBy.java
  18. 8
      app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java
  19. 4
      app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java
  20. 4
      app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java
  21. 4
      app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java
  22. 16
      app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeRpcAdapter.java
  23. 10
      app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeRpcClient.java
  24. 2
      app/src/main/java/org/transdroid/daemon/adapters/kTorrent/FileListParser.java
  25. 2
      app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java
  26. 2
      app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java
  27. 10
      app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java
  28. 18
      app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java
  29. 2
      app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java
  30. 8
      app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java
  31. 8
      app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java
  32. 6
      app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java
  33. 2
      app/src/main/java/org/transdroid/daemon/task/SetFilePriorityTask.java
  34. 2
      app/src/main/java/org/transdroid/daemon/task/SetTrackersTask.java
  35. 2
      app/src/main/java/org/transdroid/daemon/util/HttpHelper.java
  36. 7
      app/src/main/java/org/transdroid/multipart/BitCometFilePart.java

7
app/src/main/java/org/transdroid/core/gui/TorrentsActivity.java

@ -285,7 +285,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
navigationListAdapter.updateServers(applicationSettings.getAllServerSettings()); navigationListAdapter.updateServers(applicationSettings.getAllServerSettings());
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this)); navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// Add an empty labels list (which will be updated later, but the adapter needs to be created now) // Add an empty labels list (which will be updated later, but the adapter needs to be created now)
navigationListAdapter.updateLabels(new ArrayList<Label>()); navigationListAdapter.updateLabels(new ArrayList<>());
// Apply the filters list to the navigation drawer (on phones) or the dedicated side bar (i.e. on tablets) // Apply the filters list to the navigation drawer (on phones) or the dedicated side bar (i.e. on tablets)
if (filtersList != null) { if (filtersList != null) {
@ -1122,8 +1122,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
try { try {
// Write a temporary file with the torrent contents // Write a temporary file with the torrent contents
tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir()); tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
FileOutputStream output = new FileOutputStream(tempFile); try (FileOutputStream output = new FileOutputStream(tempFile)) {
try {
final byte[] buffer = new byte[1024]; final byte[] buffer = new byte[1024];
int read; int read;
while ((read = input.read(buffer)) != -1) { while ((read = input.read(buffer)) != -1) {
@ -1132,8 +1131,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
output.flush(); output.flush();
String fileName = Uri.fromFile(tempFile).toString(); String fileName = Uri.fromFile(tempFile).toString();
addTorrentByFile(fileName, title); addTorrentByFile(fileName, title);
} finally {
output.close();
} }
} catch (IOException e) { } catch (IOException e) {
log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString()); log.e(this, "Can't write input stream to " + tempFile.toString() + ": " + e.toString());

8
app/src/main/java/org/transdroid/core/gui/lists/DetailsAdapter.java

@ -78,7 +78,7 @@ public class DetailsAdapter extends MergeAdapter {
errorsSeparatorAdapter.setViewEnabled(false); errorsSeparatorAdapter.setViewEnabled(false);
errorsSeparatorAdapter.setViewVisibility(View.GONE); errorsSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(errorsSeparatorAdapter); addAdapter(errorsSeparatorAdapter);
this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>()); this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
this.errorsAdapter.setAutoLinkMask(Linkify.WEB_URLS); this.errorsAdapter.setAutoLinkMask(Linkify.WEB_URLS);
addAdapter(errorsAdapter); addAdapter(errorsAdapter);
@ -88,7 +88,7 @@ public class DetailsAdapter extends MergeAdapter {
trackersSeparatorAdapter.setViewEnabled(false); trackersSeparatorAdapter.setViewEnabled(false);
trackersSeparatorAdapter.setViewVisibility(View.GONE); trackersSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(trackersSeparatorAdapter); addAdapter(trackersSeparatorAdapter);
this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>()); this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
addAdapter(trackersAdapter); addAdapter(trackersAdapter);
// Torrent files // Torrent files
@ -97,7 +97,7 @@ public class DetailsAdapter extends MergeAdapter {
torrentFilesSeparatorAdapter.setViewEnabled(false); torrentFilesSeparatorAdapter.setViewEnabled(false);
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE); torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(torrentFilesSeparatorAdapter); addAdapter(torrentFilesSeparatorAdapter);
this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<TorrentFile>()); this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<>());
addAdapter(torrentFilesAdapter); addAdapter(torrentFilesAdapter);
} }
@ -119,7 +119,7 @@ public class DetailsAdapter extends MergeAdapter {
*/ */
public void updateTorrentFiles(List<TorrentFile> torrentFiles) { public void updateTorrentFiles(List<TorrentFile> torrentFiles) {
if (torrentFiles == null) { if (torrentFiles == null) {
torrentFilesAdapter.update(new ArrayList<TorrentFile>()); torrentFilesAdapter.update(new ArrayList<>());
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE); torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
} else { } else {
torrentFilesAdapter.update(torrentFiles); torrentFilesAdapter.update(torrentFiles);

4
app/src/main/java/org/transdroid/core/gui/lists/MergeAdapter.java

@ -39,7 +39,7 @@ import java.util.Arrays;
*/ */
public class MergeAdapter extends BaseAdapter implements SectionIndexer { public class MergeAdapter extends BaseAdapter implements SectionIndexer {
protected ArrayList<ListAdapter> pieces = new ArrayList<ListAdapter>(); protected ArrayList<ListAdapter> pieces = new ArrayList<>();
protected String noItemsText; protected String noItemsText;
/** /**
@ -287,7 +287,7 @@ public class MergeAdapter extends BaseAdapter implements SectionIndexer {
} }
public final Object[] getSections() { public final Object[] getSections() {
ArrayList<Object> sections = new ArrayList<Object>(); ArrayList<Object> sections = new ArrayList<>();
for (ListAdapter piece : pieces) { for (ListAdapter piece : pieces) {
if (piece instanceof SectionIndexer) { if (piece instanceof SectionIndexer) {

6
app/src/main/java/org/transdroid/core/gui/lists/PiecesMapView.java

@ -32,7 +32,7 @@ class PiecesMapView extends View {
} }
public void setPieces(List<Integer> pieces) { public void setPieces(List<Integer> pieces) {
this.pieces = new ArrayList<Integer>(pieces); this.pieces = new ArrayList<>(pieces);
invalidate(); invalidate();
} }
@ -59,7 +59,7 @@ class PiecesMapView extends View {
int pieceWidth; int pieceWidth;
pieceWidth = MINIMUM_PIECE_WIDTH; pieceWidth = MINIMUM_PIECE_WIDTH;
piecesScaled = new ArrayList<Integer>(); piecesScaled = new ArrayList<>();
int bucketCount = (int) Math.ceil((double) width / (double) pieceWidth); int bucketCount = (int) Math.ceil((double) width / (double) pieceWidth);
int bucketSize = (int) Math.floor((double) this.pieces.size() / (double) bucketCount); int bucketSize = (int) Math.floor((double) this.pieces.size() / (double) bucketCount);
@ -73,7 +73,7 @@ class PiecesMapView extends View {
// If this is the last bucket, throw the remainder of the pieces array into it // If this is the last bucket, throw the remainder of the pieces array into it
int end = (i == bucketCount - 1) ? this.pieces.size() : (i + 1) * bucketSize; int end = (i == bucketCount - 1) ? this.pieces.size() : (i + 1) * bucketSize;
ArrayList<Integer> bucket = new ArrayList<Integer>(this.pieces.subList(start, end)); ArrayList<Integer> bucket = new ArrayList<>(this.pieces.subList(start, end));
int doneCount = 0; int doneCount = 0;
int downloadingCount = 0; int downloadingCount = 0;

2
app/src/main/java/org/transdroid/core/gui/lists/SimpleListItemAdapter.java

@ -98,7 +98,7 @@ public class SimpleListItemAdapter extends BaseAdapter {
* @return A list of SimpleStringItem objects representing the input strings * @return A list of SimpleStringItem objects representing the input strings
*/ */
public static List<SimpleStringItem> wrapStringsList(List<String> strings) { public static List<SimpleStringItem> wrapStringsList(List<String> strings) {
ArrayList<SimpleStringItem> errors = new ArrayList<SimpleStringItem>(); ArrayList<SimpleStringItem> errors = new ArrayList<>();
if (strings != null) { if (strings != null) {
for (String string : strings) { for (String string : strings) {
errors.add(new SimpleStringItem(string)); errors.add(new SimpleStringItem(string));

6
app/src/main/java/org/transdroid/core/gui/navigation/FilterListAdapter.java

@ -65,7 +65,7 @@ public class FilterListAdapter extends MergeAdapter {
this.serverItems.update(servers); this.serverItems.update(servers);
} else { } else {
serverSeparator.setViewVisibility(View.GONE); serverSeparator.setViewVisibility(View.GONE);
this.serverItems.update(new ArrayList<SimpleListItem>()); this.serverItems.update(new ArrayList<>());
} }
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -87,7 +87,7 @@ public class FilterListAdapter extends MergeAdapter {
this.statusTypeItems.update(statusTypes); this.statusTypeItems.update(statusTypes);
} else { } else {
statusTypeSeparator.setViewVisibility(View.GONE); statusTypeSeparator.setViewVisibility(View.GONE);
this.statusTypeItems.update(new ArrayList<SimpleListItem>()); this.statusTypeItems.update(new ArrayList<>());
} }
notifyDataSetChanged(); notifyDataSetChanged();
} }
@ -109,7 +109,7 @@ public class FilterListAdapter extends MergeAdapter {
this.labelItems.update(labels); this.labelItems.update(labels);
} else { } else {
labelSeperator.setViewVisibility(View.GONE); labelSeperator.setViewVisibility(View.GONE);
this.labelItems.update(new ArrayList<SimpleListItem>()); this.labelItems.update(new ArrayList<>());
} }
notifyDataSetChanged(); notifyDataSetChanged();
} }

2
app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java

@ -73,7 +73,7 @@ public class BarcodeHelper {
activity.startActivityForResult(intent, requestCode); activity.startActivityForResult(intent, requestCode);
} catch (Exception e) { } catch (Exception e) {
// Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present // Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present
final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_barcodescannernotfound)) .setMessage(activity.getString(R.string.search_barcodescannernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, new OnClickListener() {

2
app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java

@ -53,7 +53,7 @@ public class FilePickerHelper {
activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER);
} catch (Exception e2) { } catch (Exception e2) {
// Can't start the file manager, for example with a SecurityException or when IO File Manager is not present // Can't start the file manager, for example with a SecurityException or when IO File Manager is not present
final WeakReference<Context> intentStartContext = new WeakReference<Context>(activity); final WeakReference<Context> intentStartContext = new WeakReference<>(activity);
new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(activity.getString(R.string.search_filemanagernotfound)) .setMessage(activity.getString(R.string.search_filemanagernotfound))
.setPositiveButton(android.R.string.yes, new OnClickListener() { .setPositiveButton(android.R.string.yes, new OnClickListener() {

2
app/src/main/java/org/transdroid/core/gui/search/SearchResultsFragment.java

@ -102,7 +102,7 @@ public class SearchResultsFragment extends Fragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) { public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents // Get checked torrents
List<SearchResult> checked = new ArrayList<SearchResult>(); List<SearchResult> checked = new ArrayList<>();
for (int i = 0; i < resultsList.getCheckedItemPositions().size(); i++) { for (int i = 0; i < resultsList.getCheckedItemPositions().size(); i++) {
if (resultsList.getCheckedItemPositions().valueAt(i)) { if (resultsList.getCheckedItemPositions().valueAt(i)) {
checked.add(resultsAdapter.getItem(resultsList.getCheckedItemPositions().keyAt(i))); checked.add(resultsAdapter.getItem(resultsList.getCheckedItemPositions().keyAt(i)));

2
app/src/main/java/org/transdroid/core/seedbox/SeedboxSettingsImpl.java

@ -85,7 +85,7 @@ public abstract class SeedboxSettingsImpl implements SeedboxSettings {
* seedbox-unique internal order number) * seedbox-unique internal order number)
*/ */
public List<ServerSetting> getAllServerSettings(SharedPreferences prefs, int orderOffset) { public List<ServerSetting> getAllServerSettings(SharedPreferences prefs, int orderOffset) {
List<ServerSetting> servers = new ArrayList<ServerSetting>(); List<ServerSetting> servers = new ArrayList<>();
for (int i = 0; true; i++) { for (int i = 0; true; i++) {
ServerSetting settings = getServerSetting(prefs, orderOffset, i); ServerSetting settings = getServerSetting(prefs, orderOffset, i);
if (settings != null) if (settings != null)

10
app/src/main/java/org/transdroid/daemon/DummyAdapter.java

@ -65,7 +65,7 @@ public class DummyAdapter implements IDaemonAdapter {
private List<Torrent> dummyTorrents; private List<Torrent> dummyTorrents;
private List<Label> dummyLabels; private List<Label> dummyLabels;
private boolean alternativeModeEnabled = false; private boolean alternativeModeEnabled = false;
private List<String> trackersList = new ArrayList<String>(Arrays.asList("udp://tracker.com/announce:80", private List<String> trackersList = new ArrayList<>(Arrays.asList("udp://tracker.com/announce:80",
"https://torrents.org/announce:443")); "https://torrents.org/announce:443"));
/** /**
@ -73,8 +73,8 @@ public class DummyAdapter implements IDaemonAdapter {
*/ */
public DummyAdapter(DaemonSettings settings) { public DummyAdapter(DaemonSettings settings) {
this.settings = settings; this.settings = settings;
this.dummyTorrents = new ArrayList<Torrent>(); this.dummyTorrents = new ArrayList<>();
this.dummyLabels = new ArrayList<Label>(); this.dummyLabels = new ArrayList<>();
String[] names = new String[]{"Documentary ", "Book ", "CD Image ", "Mix tape ", "App "}; String[] names = new String[]{"Documentary ", "Book ", "CD Image ", "Mix tape ", "App "};
String[] labels = new String[]{"docs", "books", "isos", "music", "software"}; String[] labels = new String[]{"docs", "books", "isos", "music", "software"};
TorrentStatus[] statuses = new TorrentStatus[]{TorrentStatus.Seeding, TorrentStatus.Downloading, TorrentStatus[] statuses = new TorrentStatus[]{TorrentStatus.Seeding, TorrentStatus.Downloading,
@ -143,7 +143,7 @@ public class DummyAdapter implements IDaemonAdapter {
case GetFileList: case GetFileList:
Torrent t = task.getTargetTorrent(); Torrent t = task.getTargetTorrent();
List<TorrentFile> dummyFiles = new ArrayList<TorrentFile>(); List<TorrentFile> dummyFiles = new ArrayList<>();
Priority[] priorities = new Priority[]{Priority.Normal, Priority.Normal, Priority.High, Priority.Low, Priority[] priorities = new Priority[]{Priority.Normal, Priority.Normal, Priority.High, Priority.Low,
Priority.Normal}; Priority.Normal};
for (int i = 1; i < 16; i++) { for (int i = 1; i < 16; i++) {
@ -265,7 +265,7 @@ public class DummyAdapter implements IDaemonAdapter {
case SetTrackers: case SetTrackers:
trackersList = new ArrayList<String>(((SetTrackersTask) task).getNewTrackers()); trackersList = new ArrayList<>(((SetTrackersTask) task).getNewTrackers());
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
case ForceRecheck: case ForceRecheck:

2
app/src/main/java/org/transdroid/daemon/Priority.java

@ -33,7 +33,7 @@ public enum Priority {
Normal(2), Normal(2),
High(3); High(3);
private static final Map<Integer, Priority> lookup = new HashMap<Integer, Priority>(); private static final Map<Integer, Priority> lookup = new HashMap<>();
static { static {
for (Priority s : EnumSet.allOf(Priority.class)) for (Priority s : EnumSet.allOf(Priority.class))

2
app/src/main/java/org/transdroid/daemon/TorrentDetails.java

@ -60,7 +60,7 @@ public final class TorrentDetails implements Parcelable {
this.errors = in.createStringArrayList(); this.errors = in.createStringArrayList();
int[] piecesarray = in.createIntArray(); int[] piecesarray = in.createIntArray();
this.pieces = new ArrayList<Integer>(piecesarray.length); this.pieces = new ArrayList<>(piecesarray.length);
for (int i : piecesarray) { for (int i : piecesarray) {
this.pieces.add(i); this.pieces.add(i);
} }

2
app/src/main/java/org/transdroid/daemon/TorrentFile.java

@ -73,7 +73,7 @@ public final class TorrentFile implements Parcelable, Comparable<TorrentFile>, F
private static Map<String, String> fillMimeTypes() { private static Map<String, String> fillMimeTypes() {
// Full mime type support list is in http://code.google.com/p/android-vlc-remote/source/browse/trunk/AndroidManifest.xml // Full mime type support list is in http://code.google.com/p/android-vlc-remote/source/browse/trunk/AndroidManifest.xml
// We use a selection of the most popular/obvious ones // We use a selection of the most popular/obvious ones
HashMap<String, String> types = new HashMap<String, String>(); HashMap<String, String> types = new HashMap<>();
// Application // Application
types.put("m4a", "application/x-extension-m4a"); types.put("m4a", "application/x-extension-m4a");
types.put("flac", "application/x-flac"); types.put("flac", "application/x-flac");

2
app/src/main/java/org/transdroid/daemon/TorrentFilesSortBy.java

@ -26,7 +26,7 @@ public enum TorrentFilesSortBy {
PartDone(2), PartDone(2),
TotalSize(3); TotalSize(3);
private static final Map<Integer, TorrentFilesSortBy> lookup = new HashMap<Integer, TorrentFilesSortBy>(); private static final Map<Integer, TorrentFilesSortBy> lookup = new HashMap<>();
static { static {
for (TorrentFilesSortBy s : EnumSet.allOf(TorrentFilesSortBy.class)) for (TorrentFilesSortBy s : EnumSet.allOf(TorrentFilesSortBy.class))

2
app/src/main/java/org/transdroid/daemon/TorrentStatus.java

@ -31,7 +31,7 @@ public enum TorrentStatus {
Error(64), Error(64),
Unknown(0); Unknown(0);
private static final Map<Integer, TorrentStatus> lookup = new HashMap<Integer, TorrentStatus>(); private static final Map<Integer, TorrentStatus> lookup = new HashMap<>();
static { static {
for (TorrentStatus s : EnumSet.allOf(TorrentStatus.class)) for (TorrentStatus s : EnumSet.allOf(TorrentStatus.class))

2
app/src/main/java/org/transdroid/daemon/TorrentsSortBy.java

@ -32,7 +32,7 @@ public enum TorrentsSortBy {
Percent(8), Percent(8),
Size(9); Size(9);
private static final Map<Integer, TorrentsSortBy> lookup = new HashMap<Integer, TorrentsSortBy>(); private static final Map<Integer, TorrentsSortBy> lookup = new HashMap<>();
static { static {
for (TorrentsSortBy s : EnumSet.allOf(TorrentsSortBy.class)) for (TorrentsSortBy s : EnumSet.allOf(TorrentsSortBy.class))

8
app/src/main/java/org/transdroid/daemon/adapters/bitComet/BitCometAdapter.java

@ -395,7 +395,7 @@ public class BitCometAdapter implements IDaemonAdapter {
// Setup form fields and post request // Setup form fields and post request
HttpPost httppost = new HttpPost(buildWebUIUrl(path)); HttpPost httppost = new HttpPost(buildWebUIUrl(path));
List<NameValuePair> params = new ArrayList<NameValuePair>(); List<NameValuePair> params = new ArrayList<>();
params.add(new BasicNameValuePair("url", url)); params.add(new BasicNameValuePair("url", url));
params.add(new BasicNameValuePair("save_path", defaultPath)); params.add(new BasicNameValuePair("save_path", defaultPath));
params.add(new BasicNameValuePair("connection", "5")); params.add(new BasicNameValuePair("connection", "5"));
@ -435,7 +435,7 @@ public class BitCometAdapter implements IDaemonAdapter {
*/ */
private ArrayList<Torrent> parseHttpTorrents(Log log, String response) throws DaemonException { private ArrayList<Torrent> parseHttpTorrents(Log log, String response) throws DaemonException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
try { try {
@ -558,7 +558,7 @@ public class BitCometAdapter implements IDaemonAdapter {
*/ */
private ArrayList<Torrent> parseXmlTorrents(String response) throws DaemonException { private ArrayList<Torrent> parseXmlTorrents(String response) throws DaemonException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
try { try {
// Use a PullParser to handle XML tags one by one // Use a PullParser to handle XML tags one by one
@ -704,7 +704,7 @@ public class BitCometAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseHttpTorrentFiles(String response, String hash) throws DaemonException { private ArrayList<TorrentFile> parseHttpTorrentFiles(String response, String hash) throws DaemonException {
// Parse response // Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
try { try {

4
app/src/main/java/org/transdroid/daemon/adapters/bitflu/BitfluAdapter.java

@ -182,7 +182,7 @@ public class BitfluAdapter implements IDaemonAdapter {
} }
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException { private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
if (results != null) { if (results != null) {
for (int i = 0; i < results.length(); i++) { for (int i = 0; i < results.length(); i++) {
@ -223,7 +223,7 @@ public class BitfluAdapter implements IDaemonAdapter {
} }
private ArrayList<TorrentFile> parseJsonShowFilesTorrent(JSONArray response) throws JSONException { private ArrayList<TorrentFile> parseJsonShowFilesTorrent(JSONArray response) throws JSONException {
ArrayList<TorrentFile> files = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> files = new ArrayList<>();
if (response != null) { if (response != null) {
for (int i = 0; i < response.length(); i++) { for (int i = 0; i < response.length(); i++) {

4
app/src/main/java/org/transdroid/daemon/adapters/buffaloNas/BuffaloNasAdapter.java

@ -269,7 +269,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
private ArrayList<Torrent> parseJsonTorrents(JSONObject response) throws JSONException { private ArrayList<Torrent> parseJsonTorrents(JSONObject response) throws JSONException {
// Parse response // Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
JSONArray all = response.getJSONArray("torrents"); JSONArray all = response.getJSONArray("torrents");
for (int i = 0; i < all.length(); i++) { for (int i = 0; i < all.length(); i++) {
JSONObject tor = all.getJSONObject(i); JSONObject tor = all.getJSONObject(i);
@ -336,7 +336,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseJsonFiles(JSONObject response, String hash) throws JSONException { private ArrayList<TorrentFile> parseJsonFiles(JSONObject response, String hash) throws JSONException {
// Parse response // Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONArray all = response.getJSONObject("torrents").getJSONArray(hash); JSONArray all = response.getJSONObject("torrents").getJSONArray(hash);
for (int i = 0; i < all.length(); i++) { for (int i = 0; i < all.length(); i++) {
JSONObject file = all.getJSONObject(i); JSONObject file = all.getJSONObject(i);

4
app/src/main/java/org/transdroid/daemon/adapters/dLinkRouterBT/DLinkRouterBTAdapter.java

@ -343,7 +343,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException { private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException {
// Parse response // Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
JSONArray rarray = response.getJSONArray(JSON_TORRENTS); JSONArray rarray = response.getJSONArray(JSON_TORRENTS);
for (int i = 0; i < rarray.length(); i++) { for (int i = 0; i < rarray.length(); i++) {
JSONObject tor = rarray.getJSONObject(i); JSONObject tor = rarray.getJSONObject(i);
@ -396,7 +396,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, String hash) throws JSONException { private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, String hash) throws JSONException {
// Parse response // Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONObject jobj = response.getJSONObject(JSON_TORRENTS); JSONObject jobj = response.getJSONObject(JSON_TORRENTS);
if (jobj != null) { if (jobj != null) {
JSONArray files = jobj.getJSONArray(hash); // "Hash id" JSONArray files = jobj.getJSONArray(hash); // "Hash id"

16
app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeRpcAdapter.java

@ -162,8 +162,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
@Override @Override
public DaemonTaskResult executeTask(Log log, DaemonTask task) { public DaemonTaskResult executeTask(Log log, DaemonTask task) {
final DelugeRpcClient client = new DelugeRpcClient(isVersion2); try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
try {
client.connect(settings); client.connect(settings);
switch (task.getMethod()) { switch (task.getMethod()) {
case Retrieve: case Retrieve:
@ -206,8 +205,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
} }
} catch (DaemonException e) { } catch (DaemonException e) {
return new DaemonTaskFailureResult(task, e); return new DaemonTaskFailureResult(task, e);
} finally {
client.close();
} }
} }
@ -224,8 +221,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
@Override @Override
public ArrayList<RemoteRssChannel> getRemoteRssChannels(Log log) throws DaemonException { public ArrayList<RemoteRssChannel> getRemoteRssChannels(Log log) throws DaemonException {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final DelugeRpcClient client = new DelugeRpcClient(isVersion2); try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
try {
client.connect(settings); client.connect(settings);
if (!hasMethod(client, RPC_METHOD_GET_RSS_CONFIG)) { if (!hasMethod(client, RPC_METHOD_GET_RSS_CONFIG)) {
@ -275,7 +271,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
} }
return channels; return channels;
} finally { } finally {
client.close();
android.util.Log.i("Alon", String.format("getRemoteRssChannels: %dms", System.currentTimeMillis() - now)); android.util.Log.i("Alon", String.format("getRemoteRssChannels: %dms", System.currentTimeMillis() - now));
} }
} }
@ -301,17 +296,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
} else { } else {
label = null; label = null;
} }
final DelugeRpcClient client = new DelugeRpcClient(isVersion2);
try { try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
client.connect(settings); client.connect(settings);
final String torrentId = (String) client final String torrentId = (String) client
.sendRequest(item.isMagnetLink() ? RPC_METHOD_ADD_MAGNET : RPC_METHOD_ADD, item.getLink(), options); .sendRequest(item.isMagnetLink() ? RPC_METHOD_ADD_MAGNET : RPC_METHOD_ADD, item.getLink(), options);
if (label != null && hasMethod(client, RPC_METHOD_SETLABEL)) { if (label != null && hasMethod(client, RPC_METHOD_SETLABEL)) {
client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label); client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label);
} }
} finally {
client.close();
} }
} }
@ -328,7 +320,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
// Get label list from server // Get label list from server
//noinspection unchecked //noinspection unchecked
final List<String> labelNames = hasLabelPlugin ? (List<String>) client.sendRequest(RPC_METHOD_GET_LABELS) : new ArrayList<String>(); final List<String> labelNames = hasLabelPlugin ? (List<String>) client.sendRequest(RPC_METHOD_GET_LABELS) : new ArrayList<>();
// Extract labels & counts from torrents. // Extract labels & counts from torrents.
final List<Label> labels = getLabels(labelNames, torrents); final List<Label> labels = getLabels(labelNames, torrents);

10
app/src/main/java/org/transdroid/daemon/adapters/deluge/DelugeRpcClient.java

@ -117,18 +117,12 @@ class DelugeRpcClient implements Closeable {
@NonNull @NonNull
private byte[] compress(byte[] bytes) throws IOException { private byte[] compress(byte[] bytes) throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream()) {
try { try (DeflaterOutputStream deltaterOut = new DeflaterOutputStream(byteOut)) {
DeflaterOutputStream deltaterOut = new DeflaterOutputStream(byteOut);
try {
deltaterOut.write(bytes); deltaterOut.write(bytes);
deltaterOut.finish(); deltaterOut.finish();
return byteOut.toByteArray(); return byteOut.toByteArray();
} finally {
deltaterOut.close();
} }
} finally {
byteOut.close();
} }
} }

2
app/src/main/java/org/transdroid/daemon/adapters/kTorrent/FileListParser.java

@ -36,7 +36,7 @@ public class FileListParser {
Priority priority = Priority.Normal; Priority priority = Priority.Normal;
// Start pulling // Start pulling
List<TorrentFile> torrents = new ArrayList<TorrentFile>(); List<TorrentFile> torrents = new ArrayList<>();
int next = xpp.nextTag(); int next = xpp.nextTag();
String name = xpp.getName(); String name = xpp.getName();

2
app/src/main/java/org/transdroid/daemon/adapters/kTorrent/KTorrentAdapter.java

@ -327,7 +327,7 @@ public class KTorrentAdapter implements IDaemonAdapter {
// Make login request // Make login request
HttpPost httppost2 = new HttpPost(buildWebUIUrl() + RPC_URL_LOGIN); HttpPost httppost2 = new HttpPost(buildWebUIUrl() + RPC_URL_LOGIN);
List<NameValuePair> params = new ArrayList<NameValuePair>(3); List<NameValuePair> params = new ArrayList<>(3);
params.add(new BasicNameValuePair(RPC_URL_LOGIN_USER, settings.getUsername())); params.add(new BasicNameValuePair(RPC_URL_LOGIN_USER, settings.getUsername()));
params.add(new BasicNameValuePair(RPC_URL_LOGIN_PASS, params.add(new BasicNameValuePair(RPC_URL_LOGIN_PASS,
"")); // Password is send (as SHA1 hex) in the challenge field "")); // Password is send (as SHA1 hex) in the challenge field

2
app/src/main/java/org/transdroid/daemon/adapters/kTorrent/StatsParser.java

@ -48,7 +48,7 @@ public class StatsParser {
int numFiles = -1; int numFiles = -1;
// Start pulling // Start pulling
List<Torrent> torrents = new ArrayList<Torrent>(); List<Torrent> torrents = new ArrayList<>();
int next = xpp.nextTag(); int next = xpp.nextTag();
String name = xpp.getName(); String name = xpp.getName();

10
app/src/main/java/org/transdroid/daemon/adapters/rTorrent/RTorrentAdapter.java

@ -397,8 +397,8 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse torrent list from response // Parse torrent list from response
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download // Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
List<Torrent> torrents = new ArrayList<Torrent>(); List<Torrent> torrents = new ArrayList<>();
Map<String, Integer> labels = new HashMap<String, Integer>(); Map<String, Integer> labels = new HashMap<>();
Object[] responseList = (Object[]) response; Object[] responseList = (Object[]) response;
for (int i = 0; i < responseList.length; i++) { for (int i = 0; i < responseList.length; i++) {
@ -520,7 +520,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
} }
} }
lastKnownLabels = new ArrayList<Label>(); lastKnownLabels = new ArrayList<>();
for (Entry<String, Integer> pair : labels.entrySet()) { for (Entry<String, Integer> pair : labels.entrySet()) {
if (pair.getKey() != null) { if (pair.getKey() != null) {
lastKnownLabels.add(new Label(pair.getKey(), pair.getValue())); lastKnownLabels.add(new Label(pair.getKey(), pair.getValue()));
@ -543,7 +543,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse torrent files from response // Parse torrent files from response
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download // Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
List<TorrentFile> files = new ArrayList<TorrentFile>(); List<TorrentFile> files = new ArrayList<>();
Object[] responseList = (Object[]) response; Object[] responseList = (Object[]) response;
for (int i = 0; i < responseList.length; i++) { for (int i = 0; i < responseList.length; i++) {
@ -650,7 +650,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse a torrent's trackers from response // Parse a torrent's trackers from response
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download // Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
List<String> trackers = new ArrayList<String>(); List<String> trackers = new ArrayList<>();
Object[] responseList = (Object[]) response; Object[] responseList = (Object[]) response;
try { try {
for (Object aResponseList : responseList) { for (Object aResponseList : responseList) {

18
app/src/main/java/org/transdroid/daemon/adapters/synology/SynologyAdapter.java

@ -196,25 +196,25 @@ public class SynologyAdapter implements IDaemonAdapter {
} }
private void removeTask(Log log, String tid) throws DaemonException { private void removeTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>(); List<String> tids = new ArrayList<>();
tids.add(tid); tids.add(tid);
removeTasks(log, tids); removeTasks(log, tids);
} }
private void pauseTask(Log log, String tid) throws DaemonException { private void pauseTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>(); List<String> tids = new ArrayList<>();
tids.add(tid); tids.add(tid);
pauseTasks(log, tids); pauseTasks(log, tids);
} }
private void resumeTask(Log log, String tid) throws DaemonException { private void resumeTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>(); List<String> tids = new ArrayList<>();
tids.add(tid); tids.add(tid);
resumeTasks(log, tids); resumeTasks(log, tids);
} }
private void pauseAllTasks(Log log) throws DaemonException { private void pauseAllTasks(Log log) throws DaemonException {
List<String> tids = new ArrayList<String>(); List<String> tids = new ArrayList<>();
for (Torrent torrent : tasksList(log)) { for (Torrent torrent : tasksList(log)) {
tids.add(torrent.getUniqueID()); tids.add(torrent.getUniqueID());
} }
@ -222,7 +222,7 @@ public class SynologyAdapter implements IDaemonAdapter {
} }
private void resumeAllTasks(Log log) throws DaemonException { private void resumeAllTasks(Log log) throws DaemonException {
List<String> tids = new ArrayList<String>(); List<String> tids = new ArrayList<>();
for (Torrent torrent : tasksList(log)) { for (Torrent torrent : tasksList(log)) {
tids.add(torrent.getUniqueID()); tids.add(torrent.getUniqueID());
} }
@ -249,7 +249,7 @@ public class SynologyAdapter implements IDaemonAdapter {
JSONArray jsonTasks = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi", JSONArray jsonTasks = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&method=list&additional=detail,transfer,tracker").getData(log).getJSONArray("tasks"); "&method=list&additional=detail,transfer,tracker").getData(log).getJSONArray("tasks");
log.d(LOG_NAME, "Tasks = " + jsonTasks.toString()); log.d(LOG_NAME, "Tasks = " + jsonTasks.toString());
List<Torrent> result = new ArrayList<Torrent>(); List<Torrent> result = new ArrayList<>();
for (int i = 0; i < jsonTasks.length(); i++) { for (int i = 0; i < jsonTasks.length(); i++) {
result.add(parseTorrent(i, jsonTasks.getJSONObject(i))); result.add(parseTorrent(i, jsonTasks.getJSONObject(i)));
} }
@ -261,7 +261,7 @@ public class SynologyAdapter implements IDaemonAdapter {
private List<TorrentFile> fileList(Log log, String torrentId) throws DaemonException { private List<TorrentFile> fileList(Log log, String torrentId) throws DaemonException {
try { try {
List<TorrentFile> result = new ArrayList<TorrentFile>(); List<TorrentFile> result = new ArrayList<>();
JSONObject jsonTask = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi", JSONObject jsonTask = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&method=getinfo&id=" + torrentId + "&additional=detail,transfer,tracker,file").getData(log) "&method=getinfo&id=" + torrentId + "&additional=detail,transfer,tracker,file").getData(log)
.getJSONArray("tasks").getJSONObject(0); .getJSONArray("tasks").getJSONObject(0);
@ -292,8 +292,8 @@ public class SynologyAdapter implements IDaemonAdapter {
} }
private TorrentDetails torrentDetails(Log log, String torrentId) throws DaemonException { private TorrentDetails torrentDetails(Log log, String torrentId) throws DaemonException {
List<String> trackers = new ArrayList<String>(); List<String> trackers = new ArrayList<>();
List<String> errors = new ArrayList<String>(); List<String> errors = new ArrayList<>();
try { try {
JSONObject jsonTorrent = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi", JSONObject jsonTorrent = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&method=getinfo&id=" + torrentId + "&additional=tracker").getData(log).getJSONArray("tasks") "&method=getinfo&id=" + torrentId + "&additional=tracker").getData(log).getJSONArray("tasks")

2
app/src/main/java/org/transdroid/daemon/adapters/tfb4rt/StatsParser.java

@ -42,7 +42,7 @@ public class StatsParser {
long upSize = -1; // Total uploaded long upSize = -1; // Total uploaded
// Start pulling // Start pulling
List<Torrent> torrents = new ArrayList<Torrent>(); List<Torrent> torrents = new ArrayList<>();
int next = xpp.nextTag(); int next = xpp.nextTag();
String name = xpp.getName(); String name = xpp.getName();
if (name.equals("html")) { if (name.equals("html")) {

8
app/src/main/java/org/transdroid/daemon/adapters/uTorrent/UTorrentAdapter.java

@ -350,7 +350,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException { private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException {
// Parse response // Parse response
ArrayList<Label> labels = new ArrayList<Label>(); ArrayList<Label> labels = new ArrayList<>();
for (int i = 0; i < lresults.length(); i++) { for (int i = 0; i < lresults.length(); i++) {
JSONArray lab = lresults.getJSONArray(i); JSONArray lab = lresults.getJSONArray(i);
String name = lab.getString(NAME_IDX); String name = lab.getString(NAME_IDX);
@ -547,7 +547,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException { private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException {
// Parse response // Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>(); ArrayList<Torrent> torrents = new ArrayList<>();
boolean createPaths = !(settings.getDownloadDir() == null || settings.getDownloadDir().equals("")); boolean createPaths = !(settings.getDownloadDir() == null || settings.getDownloadDir().equals(""));
for (int i = 0; i < results.length(); i++) { for (int i = 0; i < results.length(); i++) {
JSONArray tor = results.getJSONArray(i); JSONArray tor = results.getJSONArray(i);
@ -593,7 +593,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
if (results.length() > 0) { if (results.length() > 0) {
JSONObject tor = results.getJSONObject(0); JSONObject tor = results.getJSONObject(0);
List<String> trackers = new ArrayList<String>(); List<String> trackers = new ArrayList<>();
for (String tracker : tor.getString("trackers").split("\\r\\n")) { for (String tracker : tor.getString("trackers").split("\\r\\n")) {
// Ignore any blank lines // Ignore any blank lines
if (!tracker.trim().equals("")) { if (!tracker.trim().equals("")) {
@ -612,7 +612,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<TorrentFile> parseJsonFileListing(JSONArray results, Torrent torrent) throws JSONException { private ArrayList<TorrentFile> parseJsonFileListing(JSONArray results, Torrent torrent) throws JSONException {
// Parse response // Parse response
ArrayList<TorrentFile> files = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> files = new ArrayList<>();
boolean createPaths = boolean createPaths =
torrent != null && torrent.getLocationDir() != null && !torrent.getLocationDir().equals(""); torrent != null && torrent.getLocationDir() != null && !torrent.getLocationDir().equals("");
final String pathSep = settings.getOS().getPathSeperator(); final String pathSep = settings.getOS().getPathSeperator();

8
app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeAdapter.java

@ -351,12 +351,12 @@ public class VuzeAdapter implements IDaemonAdapter {
// We might have an empty list if no torrents are on the server // We might have an empty list if no torrents are on the server
if (response == null) { if (response == null) {
return new ArrayList<Torrent>(); return new ArrayList<>();
} }
log.d(LOG_NAME, response.toString().length() > 300 ? response.toString().substring(0, 300) + "... (" + response.toString().length() + " chars)" : response.toString()); log.d(LOG_NAME, response.toString().length() > 300 ? response.toString().substring(0, 300) + "... (" + response.toString().length() + " chars)" : response.toString());
List<Torrent> torrents = new ArrayList<Torrent>(); List<Torrent> torrents = new ArrayList<>();
// Parse torrent list from Vuze response, which is a map list of ENTRYs // Parse torrent list from Vuze response, which is a map list of ENTRYs
for (String key : response.keySet()) { for (String key : response.keySet()) {
@ -430,12 +430,12 @@ public class VuzeAdapter implements IDaemonAdapter {
// We might have an empty list // We might have an empty list
if (response == null) { if (response == null) {
return new ArrayList<TorrentFile>(); return new ArrayList<>();
} }
//DLog.d(LOG_NAME, response.toString().length() > 300? response.toString().substring(0, 300) + "... (" + response.toString().length() + " chars)": response.toString()); //DLog.d(LOG_NAME, response.toString().length() > 300? response.toString().substring(0, 300) + "... (" + response.toString().length() + " chars)": response.toString());
List<TorrentFile> files = new ArrayList<TorrentFile>(); List<TorrentFile> files = new ArrayList<>();
// Parse torrent file list from Vuze response, which is a map list of ENTRYs // Parse torrent file list from Vuze response, which is a map list of ENTRYs
for (String key : response.keySet()) { for (String key : response.keySet()) {

6
app/src/main/java/org/transdroid/daemon/adapters/vuze/VuzeXmlOverHttpClient.java

@ -291,7 +291,7 @@ public class VuzeXmlOverHttpClient {
// Consume a list of ENTRYs? // Consume a list of ENTRYs?
if (name.equals(TAG_ENTRY)) { if (name.equals(TAG_ENTRY)) {
Map<String, Object> entries = new HashMap<String, Object>(); Map<String, Object> entries = new HashMap<>();
for (int i = 0; name.equals(TAG_ENTRY); i++) { for (int i = 0; name.equals(TAG_ENTRY); i++) {
entries.put(TAG_ENTRY + i, consumeEntry(pullParser)); entries.put(TAG_ENTRY + i, consumeEntry(pullParser));
name = pullParser.getName(); name = pullParser.getName();
@ -320,7 +320,7 @@ public class VuzeXmlOverHttpClient {
String name = pullParser.getName(); String name = pullParser.getName();
// Consume the ENTRY objects // Consume the ENTRY objects
Map<String, Object> returnValues = new HashMap<String, Object>(); Map<String, Object> returnValues = new HashMap<>();
while (next == XmlPullParser.START_TAG) { while (next == XmlPullParser.START_TAG) {
if (name.equals(TAG_TORRENT) || name.equals(TAG_ANNOUNCE) || name.equals(TAG_SCRAPE) || name.equals(TAG_STATS)) { if (name.equals(TAG_TORRENT) || name.equals(TAG_ANNOUNCE) || name.equals(TAG_SCRAPE) || name.equals(TAG_STATS)) {
@ -349,7 +349,7 @@ public class VuzeXmlOverHttpClient {
String name = pullParser.getName(); String name = pullParser.getName();
// Consume bottom-level (contains no objects of its own) object // Consume bottom-level (contains no objects of its own) object
Map<String, Object> returnValues = new HashMap<String, Object>(); Map<String, Object> returnValues = new HashMap<>();
while (next == XmlPullParser.START_TAG && !(name.equals(TAG_CACHED_PROPERTY_NAMES))) { while (next == XmlPullParser.START_TAG && !(name.equals(TAG_CACHED_PROPERTY_NAMES))) {
if (name.equals(TAG_TORRENT) || name.equals(TAG_ANNOUNCE) || name.equals(TAG_SCRAPE) || name.equals(TAG_STATS)) { if (name.equals(TAG_TORRENT) || name.equals(TAG_ANNOUNCE) || name.equals(TAG_SCRAPE) || name.equals(TAG_STATS)) {

2
app/src/main/java/org/transdroid/daemon/task/SetFilePriorityTask.java

@ -40,7 +40,7 @@ public class SetFilePriorityTask extends DaemonTask {
} }
public static SetFilePriorityTask create(IDaemonAdapter adapter, Torrent targetTorrent, Priority newPriority, TorrentFile forFile) { public static SetFilePriorityTask create(IDaemonAdapter adapter, Torrent targetTorrent, Priority newPriority, TorrentFile forFile) {
ArrayList<TorrentFile> forFiles = new ArrayList<TorrentFile>(); ArrayList<TorrentFile> forFiles = new ArrayList<>();
forFiles.add(forFile); forFiles.add(forFile);
return create(adapter, targetTorrent, newPriority, forFiles); return create(adapter, targetTorrent, newPriority, forFiles);
} }

2
app/src/main/java/org/transdroid/daemon/task/SetTrackersTask.java

@ -33,7 +33,7 @@ public class SetTrackersTask extends DaemonTask {
public static SetTrackersTask create(IDaemonAdapter adapter, Torrent targetTorrent, List<String> list) { public static SetTrackersTask create(IDaemonAdapter adapter, Torrent targetTorrent, List<String> list) {
Bundle data = new Bundle(); Bundle data = new Bundle();
data.putStringArrayList("NEW_TRACKERS_LSIT", new ArrayList<String>(list)); data.putStringArrayList("NEW_TRACKERS_LSIT", new ArrayList<>(list));
return new SetTrackersTask(adapter, targetTorrent, data); return new SetTrackersTask(adapter, targetTorrent, data);
} }

2
app/src/main/java/org/transdroid/daemon/util/HttpHelper.java

@ -223,7 +223,7 @@ public class HttpHelper {
*/ */
public static Map<String, String> parseCookiePairs(String raw) { public static Map<String, String> parseCookiePairs(String raw) {
Map<String, String> pairs = new HashMap<String, String>(); Map<String, String> pairs = new HashMap<>();
int start = 0; int start = 0;
do { do {
int next = raw.indexOf(';', start); int next = raw.indexOf(';', start);

7
app/src/main/java/org/transdroid/multipart/BitCometFilePart.java

@ -213,16 +213,13 @@ public class BitCometFilePart extends PartBase {
} }
byte[] tmp = new byte[4096]; byte[] tmp = new byte[4096];
InputStream instream = source.createInputStream(); try (InputStream instream = source.createInputStream()) {
try {
int len; int len;
while ((len = instream.read(tmp)) >= 0) { while ((len = instream.read(tmp)) >= 0) {
out.write(tmp, 0, len); out.write(tmp, 0, len);
} }
} finally {
// we're done with the stream, close it
instream.close();
} }
// we're done with the stream, close it
} }
/** /**

Loading…
Cancel
Save