public static void upload(List<ArgumentWrapper> argsArray, Session currentSession) { // Get path from arguments String path = Common.getParamString(argsArray, "path"); byte[] data = Common.getParam(argsArray, "data"); File file = new File(path); BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file, true)); out.write(data); currentSession.sendFullTransmission("", ""); } catch (Exception e) { currentSession.sendFullTransmission("", e.getMessage()); } finally { // Close file if (out != null) { try { out.close(); } catch (Exception e) { } } } }
public static void fileMD5(List<ArgumentWrapper> argsArray, Session currentSession) { // Get path from arguments String path = Common.getParamString(argsArray, "path"); try { // Send the number of bytes in the file currentSession.sendFullTransmission(Common.md5SumFile(path), ""); } catch (Exception e) { currentSession.sendFullTransmission("", e.getMessage()); } }
public static void delete(List<ArgumentWrapper> argsArray, Session currentSession) { // Get path from arguments String path = Common.getParamString(argsArray, "path"); try { if (new File(path).delete()) currentSession.sendFullTransmission("", ""); else currentSession.sendFullTransmission("", "Could not delete"); } catch (Exception e) { currentSession.sendFullTransmission("", e.getMessage()); } }
public static void unzip(List<ArgumentWrapper> argsArray, Session currentSession) { // Get path from arguments String filename = Common.getParamString(argsArray, "filename"); String path = Common.getParamString(argsArray, "path"); String destination = Common.getParamString(argsArray, "destination"); // Unzip file boolean success = Common.unzipFile(filename, path, destination); if (success) currentSession.sendFullTransmission("", ""); else currentSession.sendFullTransmission("", "Unzip failed"); }
public static void fileSize(List<ArgumentWrapper> argsArray, Session currentSession) { // Get path from arguments String path = Common.getParamString(argsArray, "path"); try { File file = new File(path); // Send the size of the file if (file.exists()) currentSession.sendFullTransmission(String.valueOf(file.length()), ""); else currentSession.sendFullTransmission("", "File does not exist"); } catch (Exception e) { currentSession.sendFullTransmission("", e.getMessage()); } }
// core.version() - returns Mercury version public static void version(List<ArgumentWrapper> argsArray, Session currentSession) { String version = ""; try { version = currentSession .applicationContext .getPackageManager() .getPackageInfo(currentSession.applicationContext.getPackageName(), 0) .versionName; } catch (Exception e) { } currentSession.sendFullTransmission(version, ""); }
// core.ping() - returns "pong" public static void ping(List<ArgumentWrapper> argsArray, Session currentSession) { currentSession.sendFullTransmission("pong", ""); }