Example #1
0
  /**
   * Generar un nombre de archivo a grabar en el directorio temporal del usuario y asignarlo al
   * fileName del report.
   *
   * @return
   */
  public String generateFileNameTmp() {

    // Purgar directorio de ficheros temporales generados por gana con 2
    // horas de diferencia
    File dir = new File(EnvironmentVariables.getUserTmp());

    if (dir.list().length > 0) {

      for (String filename : dir.list()) {

        if (filename.indexOf("gana_tmp_") > -1) {

          File file = new File(EnvironmentVariables.getUserTmp() + filename);
          Date d = new Date(file.lastModified());

          if (DateUtils.getDiffHoursDates(d, new Date()) > 1) {
            file.delete();
          }
        }
      }
    }

    fileName =
        EnvironmentVariables.getUserTmp()
            + "gana_tmp_report_"
            + SystemUtils.getIdDocument()
            + ".xls";

    if (excel != null) excel.setFileName(fileName);

    return fileName;
  }
Example #2
0
  @Override
  public synchronized byte[] getBytes() throws Exception {

    if (data != null) {
      return data;
    }

    InputStream in = SystemUtils.getResource(resource);

    if (in == null) {
      throw new Exception("RESOURCE '" + resource + "' NOT FOUND.");
    }

    ByteArrayOutputStream out = new ByteArrayOutputStream();

    // you can configure the buffer size
    byte[] buffer = new byte[1024];
    while (in.read(buffer) != -1) {
      out.write(buffer);
    }

    data = out.toByteArray();

    return data;
  }