Exemplo n.º 1
0
 public T get() {
   return fileAccess.readFile(
       new Factory<T>() {
         public T create() {
           return deserialize();
         }
       });
 }
Exemplo n.º 2
0
 public void set(final T newValue) {
   fileAccess.writeFile(
       new Runnable() {
         public void run() {
           serialize(newValue);
         }
       });
 }
Exemplo n.º 3
0
  private int contatta_Peer(FileAccess file_acc, InetAddress partner, int porta) {

    /* socket per la comunicazione TCP */
    Socket socket = null;

    PersonalServer nuovo;

    if (file_acc == null || partner == null || porta == 0) {
      System.out.println(
          "## contatta_peer ha ricevuto almeno un parametro null o porta passata 0 ! ");
      return 1;
    }

    System.out.println("@ provo a contattare il Peer " + partner.getHostAddress());

    // creo il socket
    try {
      socket = new Socket(partner, porta); // TODO 4000 è default, diventerà paramentro
    } catch (IOException e1) {
      // TODO Auto-generated catch block
      System.out.println(
          "# eccezione nella creazione socket verso il peer:" + partner.getHostAddress());
      e1.printStackTrace();
      return 1;
    }

    System.out.println("@ socket creato ");
    System.out.println("@ streams ok, chiedo riguardo al file" + file_acc.getNome());

    if (socket != null) {
      nuovo = new PersonalServer(file_acc, socket, 1);
      if (nuovo != null) Peer.threads.aggiungi_down(nuovo);
      else {
        System.out.println(
            "# Problemi con la creazione dell'oggetto del Personal Server per "
                + file_acc.getNome());
        return 1;
      }
    } else {
      System.out.println("# Problemi con la creazione del socket con " + partner.getHostAddress());
      return 1;
    }

    return 0;
  }
Exemplo n.º 4
0
 public static void main(final String[] args) {
   final File targetFile = new File("D:\\abc.def");
   final File tmp = new File(targetFile.getPath() + ".frftmp");
   if (!FileAccess.compressFileGZip(targetFile, tmp)) {
     return; // error
   }
   targetFile.delete();
   tmp.renameTo(targetFile);
 }
Exemplo n.º 5
0
 public void update(final UpdateAction<T> updateAction) {
   fileAccess.updateFile(
       new Runnable() {
         public void run() {
           T oldValue = deserialize();
           T newValue = updateAction.update(oldValue);
           serialize(newValue);
         }
       });
 }