예제 #1
0
  /**
   * Allows to simulation an Exception on chunk uplaod in order to test the recovery mechanism
   *
   * @throws IOException
   */
  public static void throwSocketExceptionIfFlagFileExists() throws IOException {
    {
      File flagFile =
          new File(
              FrameworkFileUtil.getUserHomeDotKawansoftDir()
                  + File.separator
                  + "throwSocketExceptionFlag.txt");

      if (flagFile.exists()) {

        // Slow down all for our tests
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {

          e.printStackTrace();
        }

        String content = FileUtils.readFileToString(flagFile);

        if (content.contains("1")) {
          FileUtils.write(flagFile, "2");
          throw new SocketException(
              "Exception simulation on upload(): " + flagFile + " exists and contains 1");
        }
      }
    }
  }
예제 #2
0
  /** @return the Kawansoft temp directory (create it if not exists) */
  public static String getKawansoftTempDir() {

    String tempDir = FrameworkFileUtil.getUserHomeDotKawansoftDir() + File.separator + "tmp";

    File tempDirFile = new File(tempDir);
    tempDirFile.mkdirs();

    return tempDir;
  }
예제 #3
0
  /** @throws IllegalArgumentException */
  private static void createLoggerIfNotExists() throws IllegalArgumentException {

    // Nothing to do if already exists
    if (CLIENT_LOGGER != null) {
      return;
    }

    try {

      File logDir =
          new File(FrameworkFileUtil.getUserHomeDotKawansoftDir() + File.separator + "log");
      logDir.mkdirs();

      String logFilePattern = logDir.toString() + File.separator + "KawanfwClient.log";

      CLIENT_LOGGER = Logger.getLogger("ClientLogger");
      int limit = 50 * 1024 * 1024;
      Handler fh = new FileHandler(logFilePattern, limit, 4, true);
      fh.setFormatter(new SingleLineFormatterUtil(false));
      CLIENT_LOGGER.addHandler(fh);
    } catch (Exception e) {
      throw new IllegalArgumentException("Impossible to create the CLIENT_LOGGER logger", e);
    }
  }