Skip to content

Commit a1c3f98

Browse files
committed
Fix Codacy issues
1 parent b9dbd88 commit a1c3f98

File tree

8 files changed

+23
-31
lines changed

8 files changed

+23
-31
lines changed

src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.android.ddmlib.SyncService.ISyncProgressMonitor;
66
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
77
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
8+
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
89
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
910
import org.apache.log4j.Logger;
1011
import org.springframework.beans.factory.annotation.Autowired;
@@ -13,8 +14,8 @@
1314
import java.io.ByteArrayOutputStream;
1415
import java.io.File;
1516
import java.lang.reflect.Method;
17+
import java.util.ArrayList;
1618
import java.util.List;
17-
import java.util.Vector;
1819

1920
@Component
2021
public class AndroidDeviceImpl implements AndroidDevice {
@@ -31,9 +32,7 @@ public String executeCommand(String cmd) {
3132
if (logger.isDebugEnabled()) {
3233
logger.debug("executeCommand(String) - start");
3334
}
34-
35-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
36-
try {
35+
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
3736
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
3837
String returnString = new String(bos.toByteArray(), "UTF-8");
3938
if (logger.isDebugEnabled()) {
@@ -42,7 +41,6 @@ public String executeCommand(String cmd) {
4241
return returnString;
4342
} catch (Exception ex) {
4443
logger.error("executeCommand(String)", ex);
45-
4644
throw new ExecuteCommandException(cmd);
4745
}
4846
}
@@ -56,13 +54,13 @@ public List<FileInfo> list(String path) {
5654
try {
5755
String s = executeCommand("ls -l " + path);
5856
String[] entries = s.split("\r\n");
59-
Vector<FileInfo> liste = new Vector<>();
57+
List<FileInfo> fileInfos = new ArrayList<>();
6058
for (String entry : entries) {
6159
String[] data = entry.split(" ");
6260
if (data.length < 4)
6361
continue;
6462
String attributes = data[0];
65-
boolean directory = attributes.startsWith("d");
63+
boolean directory = attributes.charAt(0) == 'd';
6664
String name = data[data.length - 1];
6765

6866
FileInfo fi = new FileInfo();
@@ -72,17 +70,16 @@ public List<FileInfo> list(String path) {
7270
fi.path = path;
7371
fi.device = this;
7472

75-
liste.add(fi);
73+
fileInfos.add(fi);
7674
}
7775

7876
if (logger.isDebugEnabled()) {
7977
logger.debug("list(String) - end");
8078
}
81-
return liste;
79+
return fileInfos;
8280
} catch (Exception ex) {
8381
logger.error("list(String)", ex);
84-
85-
throw new RuntimeException(ex);
82+
throw new AndroidScreenCastRuntimeException(ex);
8683
}
8784
}
8885

@@ -117,7 +114,7 @@ public void pullFile(String removeFrom, File localTo) {
117114
} catch (Exception ex) {
118115
logger.error("pullFile(String, File)", ex);
119116

120-
throw new RuntimeException(ex);
117+
throw new AndroidScreenCastRuntimeException(ex);
121118
}
122119

123120
if (logger.isDebugEnabled()) {
@@ -133,14 +130,14 @@ public void pushFile(File localFrom, String remoteTo) {
133130

134131
try {
135132
if (device.getSyncService() == null)
136-
throw new RuntimeException("SyncService is null, ADB crashed ?");
133+
throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
137134

138135
device.getSyncService().pushFile(localFrom.getAbsolutePath(), remoteTo, SyncService.getNullProgressMonitor());
139136

140137
} catch (Exception ex) {
141138
logger.error("pushFile(File, String)", ex);
142139

143-
throw new RuntimeException(ex);
140+
throw new AndroidScreenCastRuntimeException(ex);
144141
}
145142

146143
if (logger.isDebugEnabled()) {

src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.github.xsavikx.androidscreencast.api.file;
22

33
import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
4+
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
45
import org.springframework.stereotype.Component;
56

67
import java.io.File;
8+
import java.io.IOException;
79

810
@Component
911
public class FileInfo {
@@ -19,8 +21,8 @@ public File downloadTemporary() {
1921
device.pullFile(path + name, tempFile);
2022
tempFile.deleteOnExit();
2123
return tempFile;
22-
} catch (Exception ex) {
23-
throw new RuntimeException(ex);
24+
} catch (IOException ex) {
25+
throw new IORuntimeException(ex);
2426
}
2527
}
2628

src/main/java/com/github/xsavikx/androidscreencast/api/image/SixteenBitColorModel.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
* Modified version of SixteenBitColorModel from <a href="https://android.googlesource.com/platform/tools/swt/+/master/chimpchat/src/main/java/com/android/chimpchat/adb/image/SixteenBitColorModel.java">android.chimpchat</a>
55
*/
66
public class SixteenBitColorModel extends AbstractRawImageColorModel {
7-
public SixteenBitColorModel() {
8-
super();
9-
}
107

118
@Override
129
protected int getPixel(byte[] data) {

src/main/java/com/github/xsavikx/androidscreencast/api/injector/Injector.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.github.xsavikx.androidscreencast.api.injector;
22

3-
import org.apache.log4j.Logger;
43
import org.springframework.beans.factory.annotation.Autowired;
54
import org.springframework.stereotype.Service;
65

76
import java.io.File;
87

98
@Service
109
public class Injector {
11-
private static final Logger LOGGER = Logger.getLogger(Injector.class);
1210
private final ScreenCaptureRunnable screenCaptureRunnable;
1311
private final Thread screenCaptureThread;
1412

src/main/java/com/github/xsavikx/androidscreencast/api/injector/ScreenCaptureRunnable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
@Component
2424
public class ScreenCaptureRunnable implements Runnable {
2525
private static final Logger LOGGER = Logger.getLogger(ScreenCaptureRunnable.class);
26-
private static final String MOV_FILE_TYPE = ".mov";
2726
private static final int MOV_FPS = 30;
2827
private static final float MOV_COMPRESSION_RATE = 1f;
2928
private static final int FRAME_DURATION = 10;

src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/CompositeAtom.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import javax.imageio.stream.ImageOutputStream;
1010
import java.io.IOException;
11-
import java.util.LinkedList;
11+
import java.util.List;
1212

1313
import static com.google.common.collect.Lists.newLinkedList;
1414

@@ -17,7 +17,7 @@
1717
*/
1818
public class CompositeAtom extends CommonAtom {
1919
private static final int HEADER_SIZE = 1;
20-
private final LinkedList<Atom> children;
20+
private final List<Atom> children;
2121

2222
/**
2323
* Creates a new CompositeAtom at the current position of the ImageOutputStream.
@@ -36,7 +36,7 @@ protected int getHeaderElements() {
3636

3737
public void add(Atom child) {
3838
if (children.size() > 0) {
39-
children.getLast().finish();
39+
children.get(children.size() - 1).finish();
4040
}
4141
children.add(child);
4242
}

src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
import java.awt.event.MouseAdapter;
1515
import java.awt.event.MouseEvent;
1616
import java.io.File;
17+
import java.util.ArrayList;
1718
import java.util.LinkedHashMap;
1819
import java.util.List;
1920
import java.util.Map;
20-
import java.util.Vector;
2121

2222
@Component
2323
public class JFrameExplorer extends JFrame {
@@ -64,7 +64,6 @@ public void launch() {
6464
setLocationRelativeTo(null);
6565

6666
jListFichiers.addMouseListener(new MouseAdapter() {
67-
6867
@Override
6968
public void mouseClicked(MouseEvent e) {
7069
if (e.getClickCount() == 2) {
@@ -74,7 +73,6 @@ public void mouseClicked(MouseEvent e) {
7473
launchFile(item);
7574
}
7675
}
77-
7876
});
7977
}
8078

@@ -83,7 +81,7 @@ private void displayFolder(String path) {
8381
if (fileInfos == null)
8482
fileInfos = androidDevice.list(path);
8583

86-
List<FileInfo> files = new Vector<>();
84+
List<FileInfo> files = new ArrayList<>();
8785
for (FileInfo fi2 : fileInfos) {
8886
if (fi2.directory)
8987
continue;

src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/LazyLoadingTreeNode.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
import javax.swing.tree.TreeModel;
1010
import java.awt.event.ActionEvent;
1111
import java.awt.event.KeyEvent;
12-
import java.util.Vector;
12+
import java.util.ArrayList;
13+
import java.util.List;
1314
import java.util.concurrent.ExecutionException;
1415

1516
public abstract class LazyLoadingTreeNode extends DefaultMutableTreeNode implements TreeWillExpandListener {
@@ -242,7 +243,7 @@ protected static class CancelWorkersAction extends AbstractAction {
242243
/**
243244
* the SwingWorkers
244245
*/
245-
private Vector<com.github.xsavikx.androidscreencast.ui.worker.SwingWorker<MutableTreeNode[], ?>> workers = new Vector<>();
246+
private List<com.github.xsavikx.androidscreencast.ui.worker.SwingWorker<MutableTreeNode[], ?>> workers = new ArrayList<>();
246247

247248
/**
248249
* Default constructor

0 commit comments

Comments
 (0)