/** * Prompt to confirm that the user wants to delete the JShellItem from the file system. If so, * remove it. If -f is supplied, do not prompt and confirm. If the root directory is specified, * its contents but not itself will be subject to deletion. * * @param paths the JShellItem to be removed. */ public void rm(List<String> paths) throws Exception { // Loop through the user inputs. for (String path : paths) { // Initialize the current JShellItem. JShellItem item = getItemAtPath(path, 0); if (item == null) { System.out.printf("%s: does not exist.\n", path); } else { // Keep track of the size of that JShellItem. int size = item.getSize(); if (size > 0) { List<String> recursiveList = recurseOnPath(path, true); rm(recursiveList.subList(0, size + 1)); if (item.getSize() == 0) { rm(recursiveList.subList(size + 1, size + 2)); } } else { if (item.getPath().equals("/")) { return; } // Check the -f option. if (!currentOptions_.equals("f")) { System.out.printf( "Really remove %s from %s? (y/n) ", item.getName(), item.getParentDirectory().getPath()); // Read the user input. ArrayList<String> in = readInput(); // If 'y' if (in.toString().equals("[y]")) { item.getParentDirectory().removeItem(item); // if not 'n', ask again. } else if (!in.toString().equals("[n]")) { List<String> tempStore = new ArrayList<String>(); tempStore.add(path); rm(tempStore); } // If -f is specified. } else { item.getParentDirectory().removeItem(item); } } } } }
private int vita_sociale(FileAccess file_acc, ArrayList<InetAddress> l_peers) { int contattato_ok = 0; int problemi = 0; System.out.println("@ vista sociale attivata con lista !" + l_peers.toString()); for (InetAddress i : l_peers) if (!i.getHostAddress().equals("192.168.0.10")) { System.out.println("@ confronto gli ip di: " + i.getHostAddress() + " con 192.168.0.10"); contattato_ok = contatta_Peer(file_acc, i, 4000); if (contattato_ok != 0) { System.out.println( "# il tentativo di creazione di connessione con il peer " + i.getHostAddress() + " ha fallito"); problemi = 1; } } else System.out.println("Evito di contattare il mio stesso indirizzo"); // TODO togliere questo return problemi; }
private ArrayList<InetAddress> contatta_Tracker(Descrittore descr) { InetAddress server = null; ObjectInputStream data_in; ObjectOutputStream data_out; InputStream in; OutputStream out; ArrayList<InetAddress> lista = null; /* socket per la comunicazione TCP */ SSLSocketFactory factory = null; SSLSocket socket = null; // ###### preparo l'indirizzo try { server = InetAddress.getByName("192.168.0.10"); } catch (UnknownHostException e1) { e1.printStackTrace(); } // ###### creo il socket if (descr == null) { System.out.println("## contatta_tracker di Download ha ricevuto parametro null ! "); return null; } System.out.println( "@ provo a contattare via TCP il Tracker a " + server.toString() + " porta " + descr.getTcp()); try { factory = (SSLSocketFactory) SSLSocketFactory.getDefault(); socket = (SSLSocket) factory.createSocket(server, descr.getTcp()); } catch (IOException e1) { System.out.println("# eccezione nella creazione socket verso il Tracker TCP"); e1.printStackTrace(); } System.out.println("@ socket creato "); if (factory == null || socket == null) { System.out.println("## la connessione ssl di Download ha ritornato null ! "); return null; } try { System.out.println("@ out_stream "); out = socket.getOutputStream(); System.out.println("@ out "); data_out = new ObjectOutputStream(out); System.out.println("@ in_stream "); in = socket.getInputStream(); System.out.println("@ in "); data_in = new ObjectInputStream(in); System.out.println("@ Downloader: streams ok "); data_out.writeObject(descr); // TODO Perchè ? data_out.flush(); System.out.println("@ descrittore mandato "); lista = (ArrayList<InetAddress>) data_in.readObject(); if (lista == null) System.out.println( "@ ritornata lista vuota dal tracker riguardo : " + descr.nome); // TODO sarebbe un caso plausibile else System.out.println("@ lista ricevuta : " + lista.toString()); } catch (IOException e) { System.out.println("# eccezione I/O nella creazione socket verso il Tracker TCP"); e.printStackTrace(); } catch (ClassNotFoundException e) { System.out.println("# eccezione C N F nella creazione socket verso il Tracker TCP"); e.printStackTrace(); } return lista; }