Skip to content

Commit

Permalink
Fix Codacy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
xSAVIKx committed Feb 11, 2017
1 parent b9dbd88 commit a1c3f98
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.android.ddmlib.SyncService.ISyncProgressMonitor;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -13,8 +14,8 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

@Component
public class AndroidDeviceImpl implements AndroidDevice {
Expand All @@ -31,9 +32,7 @@ public String executeCommand(String cmd) {
if (logger.isDebugEnabled()) {
logger.debug("executeCommand(String) - start");
}

ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream();) {
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
String returnString = new String(bos.toByteArray(), "UTF-8");
if (logger.isDebugEnabled()) {
Expand All @@ -42,7 +41,6 @@ public String executeCommand(String cmd) {
return returnString;
} catch (Exception ex) {
logger.error("executeCommand(String)", ex);

throw new ExecuteCommandException(cmd);
}
}
Expand All @@ -56,13 +54,13 @@ public List<FileInfo> list(String path) {
try {
String s = executeCommand("ls -l " + path);
String[] entries = s.split("\r\n");
Vector<FileInfo> liste = new Vector<>();
List<FileInfo> fileInfos = new ArrayList<>();
for (String entry : entries) {
String[] data = entry.split(" ");
if (data.length < 4)
continue;
String attributes = data[0];
boolean directory = attributes.startsWith("d");
boolean directory = attributes.charAt(0) == 'd';
String name = data[data.length - 1];

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

liste.add(fi);
fileInfos.add(fi);
}

if (logger.isDebugEnabled()) {
logger.debug("list(String) - end");
}
return liste;
return fileInfos;
} catch (Exception ex) {
logger.error("list(String)", ex);

throw new RuntimeException(ex);
throw new AndroidScreenCastRuntimeException(ex);
}
}

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

throw new RuntimeException(ex);
throw new AndroidScreenCastRuntimeException(ex);
}

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

try {
if (device.getSyncService() == null)
throw new RuntimeException("SyncService is null, ADB crashed ?");
throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");

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

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

throw new RuntimeException(ex);
throw new AndroidScreenCastRuntimeException(ex);
}

if (logger.isDebugEnabled()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.github.xsavikx.androidscreencast.api.file;

import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;

@Component
public class FileInfo {
Expand All @@ -19,8 +21,8 @@ public File downloadTemporary() {
device.pullFile(path + name, tempFile);
tempFile.deleteOnExit();
return tempFile;
} catch (Exception ex) {
throw new RuntimeException(ex);
} catch (IOException ex) {
throw new IORuntimeException(ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
* 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>
*/
public class SixteenBitColorModel extends AbstractRawImageColorModel {
public SixteenBitColorModel() {
super();
}

@Override
protected int getPixel(byte[] data) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.github.xsavikx.androidscreencast.api.injector;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.File;

@Service
public class Injector {
private static final Logger LOGGER = Logger.getLogger(Injector.class);
private final ScreenCaptureRunnable screenCaptureRunnable;
private final Thread screenCaptureThread;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
@Component
public class ScreenCaptureRunnable implements Runnable {
private static final Logger LOGGER = Logger.getLogger(ScreenCaptureRunnable.class);
private static final String MOV_FILE_TYPE = ".mov";
private static final int MOV_FPS = 30;
private static final float MOV_COMPRESSION_RATE = 1f;
private static final int FRAME_DURATION = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import javax.imageio.stream.ImageOutputStream;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

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

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

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

public void add(Atom child) {
if (children.size() > 0) {
children.getLast().finish();
children.get(children.size() - 1).finish();
}
children.add(child);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;

@Component
public class JFrameExplorer extends JFrame {
Expand Down Expand Up @@ -64,7 +64,6 @@ public void launch() {
setLocationRelativeTo(null);

jListFichiers.addMouseListener(new MouseAdapter() {

@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
Expand All @@ -74,7 +73,6 @@ public void mouseClicked(MouseEvent e) {
launchFile(item);
}
}

});
}

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

List<FileInfo> files = new Vector<>();
List<FileInfo> files = new ArrayList<>();
for (FileInfo fi2 : fileInfos) {
if (fi2.directory)
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import javax.swing.tree.TreeModel;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.util.Vector;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;

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

/**
* Default constructor
Expand Down

0 comments on commit a1c3f98

Please sign in to comment.