/**
  * Copia los archivos a utilizar por una aplicación, en el directorio de trabajos de tdderive,
  * comprime tales archivos y los divide dejando los resultados de ambas acciones en sus
  * directorios correspondientes.
  * <li>Registra los archivos de la tarea.
  * <li>Si se debe exportar se crea un directorio cuyo nombre será
  *     <tt>"tarea"+MilisegundosDesde1ºEnero1970</tt>.
  * <li>Si se exporta, se exportan los archivos bloque por bloque, asi que aquí se indica el nombre
  *     de cada bloque.
  * <li>Si no se exporta, entonces no se indican bloques, pero se indica que cada archivo está
  *     local.
  *
  * @throws ADMINExcepcion Si error.
  * @throws OIExcepcion Si error.
  */
 protected void ubicaArchivos() throws OIExcepcion, ADMINGLOExcepcion {
   int i = 0, idx = 0;
   String cNombreArchivo, cNombreComprimido, cBloque;
   tdutils.SplitInfo[] acBloques;
   PERSCoordinacion.Archivos archivoI, archivoII = null;
   File fArchivo = null;
   Iterator itr;
   Map mpArchivosACargar = new TreeMap(String.CASE_INSENSITIVE_ORDER);
   mpArchivosACargar.putAll(mpArchivos);
   mpArchivos.clear();
   itr = mpArchivosACargar.values().iterator();
   while (itr.hasNext()) {
     archivoI = (PERSCoordinacion.Archivos) itr.next();
     cNombreArchivo = archivoI.getRutaOriginal();
     fArchivo = new File(cNombreArchivo);
     // el archivo o directorio sí existe
     // se comprime en directorio de comprimidos
     cNombreComprimido = tarea.getComprimidosDir() + "/" + archivoI.getNombre();
     try {
       Zip.zipFile(cNombreComprimido, cNombreArchivo);
     } catch (IOException ex) {
       throw new ADMINGLOExcepcion("No se pudo comprimir archivo.", ex);
     }
     archivoII = new PERSCoordinacion.Archivos(this.info);
     archivoII.setNombre(archivoI.getNombre());
     archivoII.setInfoArchivo(archivoI.getInfoArchivo());
     archivoII.setSiLocal(false);
     archivoII.setEstadoArchivo(ADMINAPPIArchivos.ARCHIVO_PRESENTE);
     // prepara lista de archivos a exportar
     mpArchivos.put(archivoII.getNombre(), archivoII);
   }
 }
Example #2
0
 @Override
 default <U> Tree<Tuple2<T, U>> zip(Iterable<U> that) {
   Objects.requireNonNull(that, "that is null");
   if (isEmpty()) {
     return Empty.instance();
   } else {
     return Zip.apply((Node<T>) this, that.iterator());
   }
 }
Example #3
0
 @SuppressWarnings("unchecked")
 static <T, U> Tree<Tuple2<T, U>> apply(Node<T> node, java.util.Iterator<U> that) {
   if (!that.hasNext()) {
     return Empty.instance();
   } else {
     final Tuple2<T, U> value = Tuple.of(node.getValue(), that.next());
     final List<Node<Tuple2<T, U>>> children =
         (List<Node<Tuple2<T, U>>>)
             (Object)
                 node.getChildren().map(child -> Zip.apply(child, that)).filter(Tree::isDefined);
     return new Node<>(value, children);
   }
 }
Example #4
0
  /**
   * Service.
   *
   * @param o the o
   * @param session the session
   */
  void service(IoBuffer o, IoSession session) {
    try {
      // System.out.println(o.remaining() + "/" + o.capacity());

      session.setAttribute("last", System.currentTimeMillis());

      SimpleIoBuffer in = (SimpleIoBuffer) session.getAttribute("buf");
      if (in == null) {
        in = SimpleIoBuffer.create(4096);
        session.setAttribute("buf", in);
      }
      byte[] data = new byte[o.remaining()];
      o.get(data);
      in.append(data);

      // log.debug("recv: " + data.length + ", " +
      // session.getRemoteAddress());

      while (in.length() > 5) {
        in.mark();
        /**
         * Byte 1: head of the package<br>
         * bit 7-6: "01", indicator of MDC<br>
         * bit 5: encrypt indicator, "0": no; "1": encrypted<br>
         * bit 4: zip indicator, "0": no, "1": ziped<br>
         * bit 0-3: reserved<br>
         * Byte 2-5: length of data<br>
         * Byte[…]: data array<br>
         */
        byte head = in.read();
        /** test the head indicator, if not correct close it */
        if ((head & 0xC0) != 0x40) {
          log.info("flag is not correct! flag:" + head + ",from: " + session.getRemoteAddress());

          session.close(true);
          return;
        }

        int len = in.getInt();

        if (len <= 0 || len > MAX_SIZE) {
          log.error(
              "mdcconnector.Wrong lendth: "
                  + len
                  + "/"
                  + MAX_SIZE
                  + " - "
                  + session.getRemoteAddress());
          session.close(true);
          break;
        }

        if (in.length() < len) {
          in.reset();
          break;
        } else {
          // do it
          // log.info("stub.package.size: " + len);

          byte[] b = new byte[len];
          in.read(b);

          if (TConn.DEBUG) {
            log.debug("recv: " + Bean.toString(b));
          }

          /** test the zip flag */
          if ((head & 0x10) > 0) {
            b = Zip.unzip(b);
          }

          final TConn d = (TConn) session.getAttribute("conn");
          if (d != null) {
            /** test the encrypted flag */
            if ((head & 0x20) > 0) {
              b = DES.decode(b, d.deskey);
            }

            final byte[] bb = b;
            /** test if the packet is for mdc or app */
            new WorkerTask() {

              @Override
              public void onExecute() {
                d.process(bb);
              }
            }.schedule(0);

            session.setAttribute("last", System.currentTimeMillis());
          }
        }
      }
    } catch (Throwable e) {
      log.error("closing stub: " + session.getRemoteAddress(), e);
      session.close(true);
    }
  }
  /** Descomprime los archivos de la tarea. */
  protected void descompArchivos() throws ADMINGLOExcepcion {
    String cNombreAnt = "";
    Iterator itr;
    PERSCoordinacion.Archivos archI;
    Map mpArchListos, mpArchPresentes, mpArchAusentes;
    mpArchListos = new TreeMap(String.CASE_INSENSITIVE_ORDER);
    mpArchPresentes = new TreeMap(String.CASE_INSENSITIVE_ORDER);
    if (this.siSubtrabajo()) {
      if (this.siSubtrabajoFin()) {
        subtraV.loadArchivosSalidaListos(mpArchListos);
        subtraV.loadArchivosSalidaPresentes(mpArchPresentes);
      } else {
        subtraV.loadArchivosListos(mpArchListos);
        subtraV.loadArchivosPresentes(mpArchPresentes);
      }
    } else {
      //      // provisional [
      //      try {
      //        this.info.getConex().dbCommit();
      //      } catch (OIExcepcion e) {
      //        System.err.println("[Provisional] No pudo escribirse en la base de datos");
      //      }
      //      // provisional ]
      tarea.loadArchivosListos(mpArchListos);
      tarea.loadArchivosPresentes(mpArchPresentes);
    }
    itr = mpArchivos.values().iterator();
    while (itr.hasNext()) {
      archI = (PERSCoordinacion.Archivos) itr.next();
      if (mpArchListos.get(archI.getNombre()) != null) {
        // el archivo no se debe descomprimir, ya está listo.
      } else {
        if (mpArchPresentes.get(archI.getNombre()) != null) {
          // el archivo se debe descomprimir.
          if (this.siSubtrabajo()) {
            if (this.siSubtrabajoFin()) {
              //              Zip.unzipFile(subtrabajo.getComprimidosDir()+
              //                  "/"+archI.getNombre(),
              //                  subtrabajo.getResultadosDir());
              // tdutils.copiaArchivo()

              try {
                tdutils.copiaArchivo(
                    new File(subtraV.getSubtrabajoDir() + "/" + archI.getNombre()),
                    new File(subtraV.getResultadosDir() + "/" + archI.getNombre()));
                // tdutils.copiaArchivo(new File(subtraV.getSubtrabajoDir()+"/"+ archI.getNombre()),
                // new File(subtraV.getResultadosDir()+"/"+archI.getNombre()));
              } catch (IOException e) {
                e.printStackTrace();
              }

            } else {
              //              Zip.unzipFile(subtrabajo.getComprimidosDir()+
              //                  "/"+archI.getNombre(),
              //                  subtrabajo.getSubtrabajoDir());
            }
          } else {
            Zip.unzipFile(tarea.getComprimidosDir() + "/" + archI.getNombre(), tarea.getTareaDir());
          }
          try {
            archI.setEstadoArchivo(ADMINAPPIArchivos.ARCHIVO_LISTO);
            archI.write();
          } catch (ADMINGLOExcepcion ex) {
          }
        } else {
          // el archivo está ausente
          archI.setEstadoArchivo(ADMINAPPIArchivos.ARCHIVO_AUSENTE);
          try {
            archI.write();
          } catch (ADMINGLOExcepcion ex1) {
          }
          continue;
        }
      }
    }
  }