Browse Source

Java 7 migration

pull/559/head
TacoTheDank 5 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 @@ -285,7 +285,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
navigationListAdapter.updateServers(applicationSettings.getAllServerSettings());
navigationListAdapter.updateStatusTypes(StatusType.getAllStatusTypes(this));
// 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)
if (filtersList != null) {
@ -1122,8 +1122,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1122,8 +1122,7 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
try {
// Write a temporary file with the torrent contents
tempFile = File.createTempFile("transdroid_", ".torrent", getCacheDir());
FileOutputStream output = new FileOutputStream(tempFile);
try {
try (FileOutputStream output = new FileOutputStream(tempFile)) {
final byte[] buffer = new byte[1024];
int read;
while ((read = input.read(buffer)) != -1) {
@ -1132,8 +1131,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE @@ -1132,8 +1131,6 @@ public class TorrentsActivity extends AppCompatActivity implements TorrentTasksE
output.flush();
String fileName = Uri.fromFile(tempFile).toString();
addTorrentByFile(fileName, title);
} finally {
output.close();
}
} catch (IOException e) {
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 { @@ -78,7 +78,7 @@ public class DetailsAdapter extends MergeAdapter {
errorsSeparatorAdapter.setViewEnabled(false);
errorsSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(errorsSeparatorAdapter);
this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>());
this.errorsAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
this.errorsAdapter.setAutoLinkMask(Linkify.WEB_URLS);
addAdapter(errorsAdapter);
@ -88,7 +88,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -88,7 +88,7 @@ public class DetailsAdapter extends MergeAdapter {
trackersSeparatorAdapter.setViewEnabled(false);
trackersSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(trackersSeparatorAdapter);
this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<SimpleListItem>());
this.trackersAdapter = new SimpleListItemAdapter(context, new ArrayList<>());
addAdapter(trackersAdapter);
// Torrent files
@ -97,7 +97,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -97,7 +97,7 @@ public class DetailsAdapter extends MergeAdapter {
torrentFilesSeparatorAdapter.setViewEnabled(false);
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
addAdapter(torrentFilesSeparatorAdapter);
this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<TorrentFile>());
this.torrentFilesAdapter = new TorrentFilesAdapter(context, new ArrayList<>());
addAdapter(torrentFilesAdapter);
}
@ -119,7 +119,7 @@ public class DetailsAdapter extends MergeAdapter { @@ -119,7 +119,7 @@ public class DetailsAdapter extends MergeAdapter {
*/
public void updateTorrentFiles(List<TorrentFile> torrentFiles) {
if (torrentFiles == null) {
torrentFilesAdapter.update(new ArrayList<TorrentFile>());
torrentFilesAdapter.update(new ArrayList<>());
torrentFilesSeparatorAdapter.setViewVisibility(View.GONE);
} else {
torrentFilesAdapter.update(torrentFiles);

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

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

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

@ -32,7 +32,7 @@ class PiecesMapView extends View { @@ -32,7 +32,7 @@ class PiecesMapView extends View {
}
public void setPieces(List<Integer> pieces) {
this.pieces = new ArrayList<Integer>(pieces);
this.pieces = new ArrayList<>(pieces);
invalidate();
}
@ -59,7 +59,7 @@ class PiecesMapView extends View { @@ -59,7 +59,7 @@ class PiecesMapView extends View {
int pieceWidth;
pieceWidth = MINIMUM_PIECE_WIDTH;
piecesScaled = new ArrayList<Integer>();
piecesScaled = new ArrayList<>();
int bucketCount = (int) Math.ceil((double) width / (double) pieceWidth);
int bucketSize = (int) Math.floor((double) this.pieces.size() / (double) bucketCount);
@ -73,7 +73,7 @@ class PiecesMapView extends View { @@ -73,7 +73,7 @@ class PiecesMapView extends View {
// 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;
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 downloadingCount = 0;

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

@ -98,7 +98,7 @@ public class SimpleListItemAdapter extends BaseAdapter { @@ -98,7 +98,7 @@ public class SimpleListItemAdapter extends BaseAdapter {
* @return A list of SimpleStringItem objects representing the input strings
*/
public static List<SimpleStringItem> wrapStringsList(List<String> strings) {
ArrayList<SimpleStringItem> errors = new ArrayList<SimpleStringItem>();
ArrayList<SimpleStringItem> errors = new ArrayList<>();
if (strings != null) {
for (String string : strings) {
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 { @@ -65,7 +65,7 @@ public class FilterListAdapter extends MergeAdapter {
this.serverItems.update(servers);
} else {
serverSeparator.setViewVisibility(View.GONE);
this.serverItems.update(new ArrayList<SimpleListItem>());
this.serverItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}
@ -87,7 +87,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -87,7 +87,7 @@ public class FilterListAdapter extends MergeAdapter {
this.statusTypeItems.update(statusTypes);
} else {
statusTypeSeparator.setViewVisibility(View.GONE);
this.statusTypeItems.update(new ArrayList<SimpleListItem>());
this.statusTypeItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}
@ -109,7 +109,7 @@ public class FilterListAdapter extends MergeAdapter { @@ -109,7 +109,7 @@ public class FilterListAdapter extends MergeAdapter {
this.labelItems.update(labels);
} else {
labelSeperator.setViewVisibility(View.GONE);
this.labelItems.update(new ArrayList<SimpleListItem>());
this.labelItems.update(new ArrayList<>());
}
notifyDataSetChanged();
}

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

@ -73,7 +73,7 @@ public class BarcodeHelper { @@ -73,7 +73,7 @@ public class BarcodeHelper {
activity.startActivityForResult(intent, requestCode);
} catch (Exception e) {
// 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)
.setMessage(activity.getString(R.string.search_barcodescannernotfound))
.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 { @@ -53,7 +53,7 @@ public class FilePickerHelper {
activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER);
} catch (Exception e2) {
// 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)
.setMessage(activity.getString(R.string.search_filemanagernotfound))
.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 { @@ -102,7 +102,7 @@ public class SearchResultsFragment extends Fragment {
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
// Get checked torrents
List<SearchResult> checked = new ArrayList<SearchResult>();
List<SearchResult> checked = new ArrayList<>();
for (int i = 0; i < resultsList.getCheckedItemPositions().size(); i++) {
if (resultsList.getCheckedItemPositions().valueAt(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 { @@ -85,7 +85,7 @@ public abstract class SeedboxSettingsImpl implements SeedboxSettings {
* seedbox-unique internal order number)
*/
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++) {
ServerSetting settings = getServerSetting(prefs, orderOffset, i);
if (settings != null)

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

@ -65,7 +65,7 @@ public class DummyAdapter implements IDaemonAdapter { @@ -65,7 +65,7 @@ public class DummyAdapter implements IDaemonAdapter {
private List<Torrent> dummyTorrents;
private List<Label> dummyLabels;
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"));
/**
@ -73,8 +73,8 @@ public class DummyAdapter implements IDaemonAdapter { @@ -73,8 +73,8 @@ public class DummyAdapter implements IDaemonAdapter {
*/
public DummyAdapter(DaemonSettings settings) {
this.settings = settings;
this.dummyTorrents = new ArrayList<Torrent>();
this.dummyLabels = new ArrayList<Label>();
this.dummyTorrents = new ArrayList<>();
this.dummyLabels = new ArrayList<>();
String[] names = new String[]{"Documentary ", "Book ", "CD Image ", "Mix tape ", "App "};
String[] labels = new String[]{"docs", "books", "isos", "music", "software"};
TorrentStatus[] statuses = new TorrentStatus[]{TorrentStatus.Seeding, TorrentStatus.Downloading,
@ -143,7 +143,7 @@ public class DummyAdapter implements IDaemonAdapter { @@ -143,7 +143,7 @@ public class DummyAdapter implements IDaemonAdapter {
case GetFileList:
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.Normal};
for (int i = 1; i < 16; i++) {
@ -265,7 +265,7 @@ public class DummyAdapter implements IDaemonAdapter { @@ -265,7 +265,7 @@ public class DummyAdapter implements IDaemonAdapter {
case SetTrackers:
trackersList = new ArrayList<String>(((SetTrackersTask) task).getNewTrackers());
trackersList = new ArrayList<>(((SetTrackersTask) task).getNewTrackers());
return new DaemonTaskSuccessResult(task);
case ForceRecheck:

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

@ -33,7 +33,7 @@ public enum Priority { @@ -33,7 +33,7 @@ public enum Priority {
Normal(2),
High(3);
private static final Map<Integer, Priority> lookup = new HashMap<Integer, Priority>();
private static final Map<Integer, Priority> lookup = new HashMap<>();
static {
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 { @@ -60,7 +60,7 @@ public final class TorrentDetails implements Parcelable {
this.errors = in.createStringArrayList();
int[] piecesarray = in.createIntArray();
this.pieces = new ArrayList<Integer>(piecesarray.length);
this.pieces = new ArrayList<>(piecesarray.length);
for (int i : piecesarray) {
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 @@ -73,7 +73,7 @@ public final class TorrentFile implements Parcelable, Comparable<TorrentFile>, F
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
// 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
types.put("m4a", "application/x-extension-m4a");
types.put("flac", "application/x-flac");

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

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

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

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

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

@ -32,7 +32,7 @@ public enum TorrentsSortBy { @@ -32,7 +32,7 @@ public enum TorrentsSortBy {
Percent(8),
Size(9);
private static final Map<Integer, TorrentsSortBy> lookup = new HashMap<Integer, TorrentsSortBy>();
private static final Map<Integer, TorrentsSortBy> lookup = new HashMap<>();
static {
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 { @@ -395,7 +395,7 @@ public class BitCometAdapter implements IDaemonAdapter {
// Setup form fields and post request
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("save_path", defaultPath));
params.add(new BasicNameValuePair("connection", "5"));
@ -435,7 +435,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -435,7 +435,7 @@ public class BitCometAdapter implements IDaemonAdapter {
*/
private ArrayList<Torrent> parseHttpTorrents(Log log, String response) throws DaemonException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
try {
@ -558,7 +558,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -558,7 +558,7 @@ public class BitCometAdapter implements IDaemonAdapter {
*/
private ArrayList<Torrent> parseXmlTorrents(String response) throws DaemonException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
try {
// Use a PullParser to handle XML tags one by one
@ -704,7 +704,7 @@ public class BitCometAdapter implements IDaemonAdapter { @@ -704,7 +704,7 @@ public class BitCometAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseHttpTorrentFiles(String response, String hash) throws DaemonException {
// Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
try {

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

@ -182,7 +182,7 @@ public class BitfluAdapter implements IDaemonAdapter { @@ -182,7 +182,7 @@ public class BitfluAdapter implements IDaemonAdapter {
}
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException {
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
if (results != null) {
for (int i = 0; i < results.length(); i++) {
@ -223,7 +223,7 @@ public class BitfluAdapter implements IDaemonAdapter { @@ -223,7 +223,7 @@ public class BitfluAdapter implements IDaemonAdapter {
}
private ArrayList<TorrentFile> parseJsonShowFilesTorrent(JSONArray response) throws JSONException {
ArrayList<TorrentFile> files = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> files = new ArrayList<>();
if (response != null) {
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 { @@ -269,7 +269,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
private ArrayList<Torrent> parseJsonTorrents(JSONObject response) throws JSONException {
// Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
JSONArray all = response.getJSONArray("torrents");
for (int i = 0; i < all.length(); i++) {
JSONObject tor = all.getJSONObject(i);
@ -336,7 +336,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter { @@ -336,7 +336,7 @@ public class BuffaloNasAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseJsonFiles(JSONObject response, String hash) throws JSONException {
// Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONArray all = response.getJSONObject("torrents").getJSONArray(hash);
for (int i = 0; i < all.length(); 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 { @@ -343,7 +343,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONObject response) throws JSONException {
// Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
JSONArray rarray = response.getJSONArray(JSON_TORRENTS);
for (int i = 0; i < rarray.length(); i++) {
JSONObject tor = rarray.getJSONObject(i);
@ -396,7 +396,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter { @@ -396,7 +396,7 @@ public class DLinkRouterBTAdapter implements IDaemonAdapter {
private ArrayList<TorrentFile> parseJsonFileList(JSONObject response, String hash) throws JSONException {
// Parse response
ArrayList<TorrentFile> torrentfiles = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> torrentfiles = new ArrayList<>();
JSONObject jobj = response.getJSONObject(JSON_TORRENTS);
if (jobj != null) {
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 { @@ -162,8 +162,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
@Override
public DaemonTaskResult executeTask(Log log, DaemonTask task) {
final DelugeRpcClient client = new DelugeRpcClient(isVersion2);
try {
try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
client.connect(settings);
switch (task.getMethod()) {
case Retrieve:
@ -206,8 +205,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -206,8 +205,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
}
} catch (DaemonException e) {
return new DaemonTaskFailureResult(task, e);
} finally {
client.close();
}
}
@ -224,8 +221,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -224,8 +221,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
@Override
public ArrayList<RemoteRssChannel> getRemoteRssChannels(Log log) throws DaemonException {
final long now = System.currentTimeMillis();
final DelugeRpcClient client = new DelugeRpcClient(isVersion2);
try {
try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
client.connect(settings);
if (!hasMethod(client, RPC_METHOD_GET_RSS_CONFIG)) {
@ -275,7 +271,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -275,7 +271,6 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
}
return channels;
} finally {
client.close();
android.util.Log.i("Alon", String.format("getRemoteRssChannels: %dms", System.currentTimeMillis() - now));
}
}
@ -301,17 +296,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -301,17 +296,14 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
} else {
label = null;
}
final DelugeRpcClient client = new DelugeRpcClient(isVersion2);
try {
try (DelugeRpcClient client = new DelugeRpcClient(isVersion2)) {
client.connect(settings);
final String torrentId = (String) client
.sendRequest(item.isMagnetLink() ? RPC_METHOD_ADD_MAGNET : RPC_METHOD_ADD, item.getLink(), options);
if (label != null && hasMethod(client, RPC_METHOD_SETLABEL)) {
client.sendRequest(RPC_METHOD_SETLABEL, torrentId, label);
}
} finally {
client.close();
}
}
@ -328,7 +320,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -328,7 +320,7 @@ public class DelugeRpcAdapter implements IDaemonAdapter, RemoteRssSupplier {
// Get label list from server
//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.
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 { @@ -117,18 +117,12 @@ class DelugeRpcClient implements Closeable {
@NonNull
private byte[] compress(byte[] bytes) throws IOException {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
try {
DeflaterOutputStream deltaterOut = new DeflaterOutputStream(byteOut);
try {
try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream()) {
try (DeflaterOutputStream deltaterOut = new DeflaterOutputStream(byteOut)) {
deltaterOut.write(bytes);
deltaterOut.finish();
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 { @@ -36,7 +36,7 @@ public class FileListParser {
Priority priority = Priority.Normal;
// Start pulling
List<TorrentFile> torrents = new ArrayList<TorrentFile>();
List<TorrentFile> torrents = new ArrayList<>();
int next = xpp.nextTag();
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 { @@ -327,7 +327,7 @@ public class KTorrentAdapter implements IDaemonAdapter {
// Make login request
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_PASS,
"")); // 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 { @@ -48,7 +48,7 @@ public class StatsParser {
int numFiles = -1;
// Start pulling
List<Torrent> torrents = new ArrayList<Torrent>();
List<Torrent> torrents = new ArrayList<>();
int next = xpp.nextTag();
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 { @@ -397,8 +397,8 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse torrent list from response
// Formatted as Object[][], see http://libtorrent.rakshasa.no/wiki/RTorrentCommands#Download
List<Torrent> torrents = new ArrayList<Torrent>();
Map<String, Integer> labels = new HashMap<String, Integer>();
List<Torrent> torrents = new ArrayList<>();
Map<String, Integer> labels = new HashMap<>();
Object[] responseList = (Object[]) response;
for (int i = 0; i < responseList.length; i++) {
@ -520,7 +520,7 @@ public class RTorrentAdapter implements IDaemonAdapter { @@ -520,7 +520,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
}
}
lastKnownLabels = new ArrayList<Label>();
lastKnownLabels = new ArrayList<>();
for (Entry<String, Integer> pair : labels.entrySet()) {
if (pair.getKey() != null) {
lastKnownLabels.add(new Label(pair.getKey(), pair.getValue()));
@ -543,7 +543,7 @@ public class RTorrentAdapter implements IDaemonAdapter { @@ -543,7 +543,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse torrent files from response
// 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;
for (int i = 0; i < responseList.length; i++) {
@ -650,7 +650,7 @@ public class RTorrentAdapter implements IDaemonAdapter { @@ -650,7 +650,7 @@ public class RTorrentAdapter implements IDaemonAdapter {
// Parse a torrent's trackers from response
// 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;
try {
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 { @@ -196,25 +196,25 @@ public class SynologyAdapter implements IDaemonAdapter {
}
private void removeTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>();
List<String> tids = new ArrayList<>();
tids.add(tid);
removeTasks(log, tids);
}
private void pauseTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>();
List<String> tids = new ArrayList<>();
tids.add(tid);
pauseTasks(log, tids);
}
private void resumeTask(Log log, String tid) throws DaemonException {
List<String> tids = new ArrayList<String>();
List<String> tids = new ArrayList<>();
tids.add(tid);
resumeTasks(log, tids);
}
private void pauseAllTasks(Log log) throws DaemonException {
List<String> tids = new ArrayList<String>();
List<String> tids = new ArrayList<>();
for (Torrent torrent : tasksList(log)) {
tids.add(torrent.getUniqueID());
}
@ -222,7 +222,7 @@ public class SynologyAdapter implements IDaemonAdapter { @@ -222,7 +222,7 @@ public class SynologyAdapter implements IDaemonAdapter {
}
private void resumeAllTasks(Log log) throws DaemonException {
List<String> tids = new ArrayList<String>();
List<String> tids = new ArrayList<>();
for (Torrent torrent : tasksList(log)) {
tids.add(torrent.getUniqueID());
}
@ -249,7 +249,7 @@ public class SynologyAdapter implements IDaemonAdapter { @@ -249,7 +249,7 @@ public class SynologyAdapter implements IDaemonAdapter {
JSONArray jsonTasks = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&method=list&additional=detail,transfer,tracker").getData(log).getJSONArray("tasks");
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++) {
result.add(parseTorrent(i, jsonTasks.getJSONObject(i)));
}
@ -261,7 +261,7 @@ public class SynologyAdapter implements IDaemonAdapter { @@ -261,7 +261,7 @@ public class SynologyAdapter implements IDaemonAdapter {
private List<TorrentFile> fileList(Log log, String torrentId) throws DaemonException {
try {
List<TorrentFile> result = new ArrayList<TorrentFile>();
List<TorrentFile> result = new ArrayList<>();
JSONObject jsonTask = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&method=getinfo&id=" + torrentId + "&additional=detail,transfer,tracker,file").getData(log)
.getJSONArray("tasks").getJSONObject(0);
@ -292,8 +292,8 @@ public class SynologyAdapter implements IDaemonAdapter { @@ -292,8 +292,8 @@ public class SynologyAdapter implements IDaemonAdapter {
}
private TorrentDetails torrentDetails(Log log, String torrentId) throws DaemonException {
List<String> trackers = new ArrayList<String>();
List<String> errors = new ArrayList<String>();
List<String> trackers = new ArrayList<>();
List<String> errors = new ArrayList<>();
try {
JSONObject jsonTorrent = authGet(log, "SYNO.DownloadStation.Task", "1", "DownloadStation/task.cgi",
"&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 { @@ -42,7 +42,7 @@ public class StatsParser {
long upSize = -1; // Total uploaded
// Start pulling
List<Torrent> torrents = new ArrayList<Torrent>();
List<Torrent> torrents = new ArrayList<>();
int next = xpp.nextTag();
String name = xpp.getName();
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 { @@ -350,7 +350,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<Label> parseJsonRetrieveGetLabels(JSONArray lresults) throws JSONException {
// Parse response
ArrayList<Label> labels = new ArrayList<Label>();
ArrayList<Label> labels = new ArrayList<>();
for (int i = 0; i < lresults.length(); i++) {
JSONArray lab = lresults.getJSONArray(i);
String name = lab.getString(NAME_IDX);
@ -547,7 +547,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -547,7 +547,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<Torrent> parseJsonRetrieveTorrents(JSONArray results) throws JSONException {
// Parse response
ArrayList<Torrent> torrents = new ArrayList<Torrent>();
ArrayList<Torrent> torrents = new ArrayList<>();
boolean createPaths = !(settings.getDownloadDir() == null || settings.getDownloadDir().equals(""));
for (int i = 0; i < results.length(); i++) {
JSONArray tor = results.getJSONArray(i);
@ -593,7 +593,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -593,7 +593,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
if (results.length() > 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")) {
// Ignore any blank lines
if (!tracker.trim().equals("")) {
@ -612,7 +612,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier { @@ -612,7 +612,7 @@ public class UTorrentAdapter implements IDaemonAdapter, RemoteRssSupplier {
private ArrayList<TorrentFile> parseJsonFileListing(JSONArray results, Torrent torrent) throws JSONException {
// Parse response
ArrayList<TorrentFile> files = new ArrayList<TorrentFile>();
ArrayList<TorrentFile> files = new ArrayList<>();
boolean createPaths =
torrent != null && torrent.getLocationDir() != null && !torrent.getLocationDir().equals("");
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 { @@ -351,12 +351,12 @@ public class VuzeAdapter implements IDaemonAdapter {
// We might have an empty list if no torrents are on the server
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());
List<Torrent> torrents = new ArrayList<Torrent>();
List<Torrent> torrents = new ArrayList<>();
// Parse torrent list from Vuze response, which is a map list of ENTRYs
for (String key : response.keySet()) {
@ -430,12 +430,12 @@ public class VuzeAdapter implements IDaemonAdapter { @@ -430,12 +430,12 @@ public class VuzeAdapter implements IDaemonAdapter {
// We might have an empty list
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());
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
for (String key : response.keySet()) {

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

@ -291,7 +291,7 @@ public class VuzeXmlOverHttpClient { @@ -291,7 +291,7 @@ public class VuzeXmlOverHttpClient {
// Consume a list of ENTRYs?
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++) {
entries.put(TAG_ENTRY + i, consumeEntry(pullParser));
name = pullParser.getName();
@ -320,7 +320,7 @@ public class VuzeXmlOverHttpClient { @@ -320,7 +320,7 @@ public class VuzeXmlOverHttpClient {
String name = pullParser.getName();
// Consume the ENTRY objects
Map<String, Object> returnValues = new HashMap<String, Object>();
Map<String, Object> returnValues = new HashMap<>();
while (next == XmlPullParser.START_TAG) {
if (name.equals(TAG_TORRENT) || name.equals(TAG_ANNOUNCE) || name.equals(TAG_SCRAPE) || name.equals(TAG_STATS)) {
@ -349,7 +349,7 @@ public class VuzeXmlOverHttpClient { @@ -349,7 +349,7 @@ public class VuzeXmlOverHttpClient {
String name = pullParser.getName();
// 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))) {
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 { @@ -40,7 +40,7 @@ public class SetFilePriorityTask extends DaemonTask {
}
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);
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 { @@ -33,7 +33,7 @@ public class SetTrackersTask extends DaemonTask {
public static SetTrackersTask create(IDaemonAdapter adapter, Torrent targetTorrent, List<String> list) {
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);
}

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

@ -223,7 +223,7 @@ public class HttpHelper { @@ -223,7 +223,7 @@ public class HttpHelper {
*/
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;
do {
int next = raw.indexOf(';', start);

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

@ -213,16 +213,13 @@ public class BitCometFilePart extends PartBase { @@ -213,16 +213,13 @@ public class BitCometFilePart extends PartBase {
}
byte[] tmp = new byte[4096];
InputStream instream = source.createInputStream();
try {
try (InputStream instream = source.createInputStream()) {
int len;
while ((len = instream.read(tmp)) >= 0) {
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