@Override public void run() { try { Message msgToSend = messages.take(); Client[] copyOfClients; synchronized (clients) { copyOfClients = new Client[clients.size()]; for (int i = 0; i < copyOfClients.length; i++) { copyOfClients[i] = clients.take(); clients.add(copyOfClients[i]); } } for (int i = 0; i < copyOfClients.length; i++) { BufferedWriter writer = copyOfClients[i].getWriter(); writer.write(msgToSend.getMessage()); writer.newLine(); writer.flush(); } pool.submit(this); } catch (InterruptedException | IOException e) { e.printStackTrace(); } pool.execute(this); }
@Override public void run() { Message tempMessage = null; try { Client tempClient = clients.take(); clients.add(tempClient); BufferedReader reader = tempClient.getReader(); StringBuilder sb = new StringBuilder(); Thread.sleep(1000); while (reader.ready()) { sb.append(reader.readLine()); tempMessage = new Message(tempClient.getId(), sb.toString()); messages.add(tempMessage); clients.add(tempClient); // pool.submit(this); System.out.println(sb.toString()); } } catch (InterruptedException | IOException e) { clients.remove(tempMessage); e.printStackTrace(); } pool.execute(this); }
public HashMap<String, String> setIOSWebKitProxyPorts(String device_udid) throws Exception { try { int webkitproxyport = ap.getPort(); deviceMap.put(device_udid, Integer.toString(webkitproxyport)); } catch (InterruptedException | IOException e) { e.printStackTrace(); } return deviceMap; }
// TODO Создать метод бла-бла private static void clearScreen() { final String OS = System.getProperty("os.name"); if (OS.contains("Windows")) { try { new ProcessBuilder("cmd", "/c", "cls").inheritIO().start().waitFor(); } catch (InterruptedException | IOException e) { e.printStackTrace(); } } else { // ANSI_CLS and ANSI_HOME System.out.print("\u001b[2J\u001b[H"); System.out.flush(); } }
@Override public void run() { try { progressBar.setString(null); progressBar.setValue(0); toExchangeBtn.setEnabled(false); toExchangeBtn.setSelected(false); DirectoryHandler.checkFtpDirectory( departmentName); // проверяем наличие папки "номер_отдела" на FTP сервере DirectoryHandler.checkLocalDirectory( departmentName); // проверяем наличие папки "номер_отдела" на локальном компьютере boolean isUpdate = downloadOrders(); // загружаем информацию о новых заказах if (isUpdate == true) { // если новые заказы есть: downloadFile(); // загружаем swnd5.arc activeDepartment.setOrdersList(ordersList); // прикрепляем список новых заказов к отделу toExchangeBtn.setEnabled(true); progressBar.setString("Загружено"); } else { // если нет новых заказов: toExchangeBtn.setEnabled(false); // блокируем кнопку "на обмен" progressBar.setString("Нет новых данных"); } } catch (InterruptedException | IOException ex) { String errorMsg; if (ex.toString().contains("FileNotFoundException")) { errorMsg = "Файл обмена отсутствует, либо указан неверный путь."; } else if (ex.toString().contains("NoRouteToHostException")) { errorMsg = "Ошибка соединения с интернетом."; } else if (ex.toString().contains("FtpLoginException")) { errorMsg = "Ошибка доступа к FTP-серверу. Неверный логин или пароль."; } else if (ex.toString().contains("UnknownHostException")) { errorMsg = "Ошибка доступа к FTP-серверу. Неверный IP-адрес."; } else { errorMsg = "Другая ошибка."; } JOptionPane.showMessageDialog( null, errorMsg + "\r\nКод ошибки: " + ex.toString(), "Отдел №" + departmentName, JOptionPane.ERROR_MESSAGE); progressBar.setString("Ошибка"); toExchangeBtn.setEnabled(false); } finally { progressBar.setValue(100); } }
public Map<String, String> getIOSUDIDHash() { try { String getIOSDeviceID = commandPrompt.runCommand("idevice_id --list"); if (getIOSDeviceID == null || getIOSDeviceID.equalsIgnoreCase("") || getIOSDeviceID.isEmpty()) { return null; } else { String[] lines = getIOSDeviceID.split("\n"); for (int i = 0; i < lines.length; i++) { lines[i] = lines[i].replaceAll("\\s+", ""); devices.put("deviceID" + i, lines[i]); } return devices; } } catch (InterruptedException | IOException e) { e.printStackTrace(); return null; } }
public static boolean requestPermissions(Context context) { if (context .getPackageManager() .checkPermission(android.Manifest.permission.READ_LOGS, context.getPackageName()) == 0) { return true; } // Attempt to grant the READ_LOGS permission ourselves String[] command = new String[] { "su", "-c", String.format("pm grant %s android.permission.READ_LOGS", context.getPackageName()) }; try { // Successful exit means we're root return Runtime.getRuntime().exec(command).waitFor() == 0; } catch (InterruptedException | IOException e) { Log.e(LogCatReader.class.getName(), e.toString()); } return false; }