コード例 #1
0
  public void putf(NslData data) {
    try {
      StringBuffer strbuf = new StringBuffer();

      strbuf.append(data.nslGetParent().nslGetRealName()); //  Object name
      strbuf.append("." + data.nslGetName() + " ");
      strbuf.append(data.getDataType() + " "); //  Class name
      strbuf.append(data.getDimensions() + " "); //  Dimension

      strbuf.append("{ "); //  Sizes
      int dim[] = data.getSizes();
      for (int i = 0; i < data.getDimensions(); i++) {
        strbuf.append(dim[i] + " ");
      }
      strbuf.append("} ");

      strbuf.append("{ "); //  Data
      strbuf.append(data.toString());
      strbuf.append("} ");

      pwr.println(strbuf.toString());

      if (pwr.checkError()) {
        System.err.println("NslFile: An error happened while writing in file: " + name);
      }
    } catch (Exception e) {
      System.err.println("NslFile: Can't write line in file " + name);
    }
  }
コード例 #2
0
ファイル: IniEditor.java プロジェクト: xiaoran27/packet
 /**
  * Prints this section to a print writer.
  *
  * @param writer where to write
  * @throws IOException at an I/O problem
  */
 public void save(PrintWriter writer) throws IOException {
   Iterator<Line> it = this.lines.iterator();
   while (it.hasNext()) {
     writer.println(it.next().toString());
   }
   if (writer.checkError()) {
     throw new IOException();
   }
 }
コード例 #3
0
 public void puts(NslData data) {
   try {
     pwr.println(data.toString());
     if (pwr.checkError()) {
       System.err.println("NslFile: An error happened while writing in file: " + name);
     }
   } catch (Exception e) {
     System.err.println("NslFile: Can't write line in file " + name);
   }
 }
コード例 #4
0
 public void puts(boolean value) {
   try {
     pwr.println(value);
     if (pwr.checkError()) {
       System.err.println("NslFile: An error happened while writing in file: " + name);
     }
   } catch (Exception e) {
     System.err.println("NslFile: Can't write line in file " + name);
   }
 }
コード例 #5
0
 public void puts(Object obj) {
   try {
     Object temp = transform(obj);
     pwr.println(temp.toString());
     if (pwr.checkError()) {
       System.err.println("NslFile: An error happened while writing in file: " + name);
     }
   } catch (Exception e) {
     System.err.println("NslFile: Can't write line in file " + name);
   }
 }
コード例 #6
0
  private void write(int record_type, long[] line_stats) {
    synchronized (this) {
      try {
        final long now = SystemTime.getCurrentTime();

        final long now_mins = now / (1000 * 60);

        String[] bits = utc_date_format.format(new Date(now)).split(",");

        String year = bits[0];
        String month = bits[1];
        String day = bits[2];

        String current_rel_file = year + File.separator + month + File.separator + day + ".dat";

        String line;

        String stats_str = "";

        if (record_type == RT_SESSION_START) {

          // absolute values

          for (int i = 0; i < line_stats.length; i++) {

            stats_str += "," + line_stats[i];

            line_stats_prev[i] = 0;
          }

          day_cache = null;

        } else {

          // relative values

          long[] diffs = new long[STAT_ENTRY_COUNT];

          for (int i = 0; i < line_stats.length; i++) {

            long diff = line_stats[i] - line_stats_prev[i];

            session_total += diff;

            diffs[i] = diff;

            stats_str += "," + diff;

            line_stats_prev[i] = line_stats[i];

            stat_averages[i].update(diff);
          }

          if (day_cache != null) {

            if (day_cache.isForDay(year, month, day)) {

              day_cache.addRecord(now_mins, diffs);
            }
          }
        }

        if (record_type != RT_SESSION_STATS) {

          line =
              (record_type == RT_SESSION_START ? "s," : "e,")
                  + VERSION
                  + ","
                  + now_mins
                  + stats_str;

        } else {

          line = stats_str.substring(1);
        }

        if (writer == null || !writer_rel_file.equals(current_rel_file)) {

          // first open of a file or file switch

          if (writer != null) {

            // file switch

            if (record_type != RT_SESSION_START) {

              writer.println(line);
            }

            writer.close();

            if (writer.checkError()) {

              writer = null;

              throw (new IOException("Write faled"));
            }

            writer = null;
          }

          // no point in opening a new file just to record the session-end

          if (record_type != RT_SESSION_END) {

            File file = new File(stats_dir, current_rel_file);

            file.getParentFile().mkdirs();

            writer = new PrintWriter(new FileWriter(file, true));

            writer_rel_file = current_rel_file;

            if (record_type == RT_SESSION_START) {

              writer.println(line);

            } else {

              // first entry in a new file, files always start with a session-start so they
              // can be processed in isolation so reset the session data and start a new one

              st_p_sent += line_stats[0];
              st_d_sent += line_stats[1];
              st_p_received += line_stats[2];
              st_d_received += line_stats[3];
              st_dht_sent += line_stats[4];
              st_dht_received += line_stats[5];

              ss_p_sent += line_stats[0];
              ss_d_sent += line_stats[1];
              ss_p_received += line_stats[2];
              ss_d_received += line_stats[3];
              ss_dht_sent += line_stats[4];
              ss_dht_received += line_stats[5];

              stats_str = "";

              long[] st_stats =
                  new long[] {
                    st_p_sent, st_d_sent, st_p_received, st_d_received, st_dht_sent, st_dht_received
                  };

              for (int i = 0; i < st_stats.length; i++) {

                stats_str += "," + st_stats[i];

                line_stats_prev[i] = 0;
              }

              line = "s," + VERSION + "," + now_mins + stats_str;

              writer.println(line);
            }
          }
        } else {

          writer.println(line);
        }

      } catch (Throwable e) {

        Debug.out("Failed to write long term stats", e);

      } finally {

        if (writer != null) {

          if (record_type == RT_SESSION_END) {

            writer.close();
          }

          if (writer.checkError()) {

            Debug.out("Failed to write long term stats");

            writer.close();

            writer = null;

          } else {

            if (record_type == RT_SESSION_END) {

              writer = null;
            }
          }
        }
      }
    }

    if (record_type != RT_SESSION_END) {

      final List<LongTermStatsListener> to_fire = new ArrayList<LongTermStatsListener>();

      for (Object[] entry : listeners) {

        long diff = session_total - (Long) entry[2];

        if (diff >= (Long) entry[1]) {

          entry[2] = session_total;

          to_fire.add((LongTermStatsListener) entry[0]);
        }
      }

      if (to_fire.size() > 0) {

        dispatcher.dispatch(
            new AERunnable() {
              @Override
              public void runSupport() {
                for (LongTermStatsListener l : to_fire) {

                  try {
                    l.updated(LongTermStatsImpl.this);

                  } catch (Throwable e) {

                    Debug.out(e);
                  }
                }
              }
            });
      }
    }
  }
コード例 #7
0
  /**
   * Writes the given configuration.
   *
   * @param configuration the configuration that is to be written out.
   * @throws IOException if an IO error occurs while writing the configuration.
   */
  public void write(Configuration configuration) throws IOException {
    // Write the program class path (input and output entries).
    writeJarOptions(
        ConfigurationConstants.INJARS_OPTION,
        ConfigurationConstants.OUTJARS_OPTION,
        configuration.programJars);
    writer.println();

    // Write the library class path (output entries only).
    writeJarOptions(
        ConfigurationConstants.LIBRARYJARS_OPTION,
        ConfigurationConstants.LIBRARYJARS_OPTION,
        configuration.libraryJars);
    writer.println();

    // Write the other options.
    writeOption(
        ConfigurationConstants.SKIP_NON_PUBLIC_LIBRARY_CLASSES_OPTION,
        configuration.skipNonPublicLibraryClasses);
    writeOption(
        ConfigurationConstants.DONT_SKIP_NON_PUBLIC_LIBRARY_CLASS_MEMBERS_OPTION,
        !configuration.skipNonPublicLibraryClassMembers);
    writeOption(ConfigurationConstants.KEEP_DIRECTORIES_OPTION, configuration.keepDirectories);
    writeOption(
        ConfigurationConstants.TARGET_OPTION,
        ClassUtil.externalClassVersion(configuration.targetClassVersion));
    writeOption(
        ConfigurationConstants.FORCE_PROCESSING_OPTION,
        configuration.lastModified == Long.MAX_VALUE);

    writeOption(ConfigurationConstants.DONT_SHRINK_OPTION, !configuration.shrink);
    writeOption(ConfigurationConstants.PRINT_USAGE_OPTION, configuration.printUsage);

    writeOption(ConfigurationConstants.DONT_OPTIMIZE_OPTION, !configuration.optimize);
    writeOption(ConfigurationConstants.OPTIMIZATIONS, configuration.optimizations);
    writeOption(ConfigurationConstants.OPTIMIZATION_PASSES, configuration.optimizationPasses);
    writeOption(
        ConfigurationConstants.ALLOW_ACCESS_MODIFICATION_OPTION,
        configuration.allowAccessModification);
    writeOption(
        ConfigurationConstants.MERGE_INTERFACES_AGGRESSIVELY_OPTION,
        configuration.mergeInterfacesAggressively);

    writeOption(ConfigurationConstants.DONT_OBFUSCATE_OPTION, !configuration.obfuscate);
    writeOption(ConfigurationConstants.PRINT_MAPPING_OPTION, configuration.printMapping);
    writeOption(ConfigurationConstants.APPLY_MAPPING_OPTION, configuration.applyMapping);
    writeOption(
        ConfigurationConstants.OBFUSCATION_DICTIONARY_OPTION, configuration.obfuscationDictionary);
    writeOption(
        ConfigurationConstants.CLASS_OBFUSCATION_DICTIONARY_OPTION,
        configuration.classObfuscationDictionary);
    writeOption(
        ConfigurationConstants.PACKAGE_OBFUSCATION_DICTIONARY_OPTION,
        configuration.packageObfuscationDictionary);
    writeOption(
        ConfigurationConstants.OVERLOAD_AGGRESSIVELY_OPTION, configuration.overloadAggressively);
    writeOption(
        ConfigurationConstants.USE_UNIQUE_CLASS_MEMBER_NAMES_OPTION,
        configuration.useUniqueClassMemberNames);
    writeOption(
        ConfigurationConstants.DONT_USE_MIXED_CASE_CLASS_NAMES_OPTION,
        !configuration.useMixedCaseClassNames);
    writeOption(
        ConfigurationConstants.KEEP_PACKAGE_NAMES_OPTION, configuration.keepPackageNames, true);
    writeOption(
        ConfigurationConstants.FLATTEN_PACKAGE_HIERARCHY_OPTION,
        configuration.flattenPackageHierarchy,
        true);
    writeOption(
        ConfigurationConstants.REPACKAGE_CLASSES_OPTION, configuration.repackageClasses, true);
    writeOption(ConfigurationConstants.KEEP_ATTRIBUTES_OPTION, configuration.keepAttributes);
    writeOption(
        ConfigurationConstants.KEEP_PARAMETER_NAMES_OPTION, configuration.keepParameterNames);
    writeOption(
        ConfigurationConstants.RENAME_SOURCE_FILE_ATTRIBUTE_OPTION,
        configuration.newSourceFileAttribute);
    writeOption(
        ConfigurationConstants.ADAPT_CLASS_STRINGS_OPTION, configuration.adaptClassStrings, true);
    writeOption(
        ConfigurationConstants.ADAPT_RESOURCE_FILE_NAMES_OPTION,
        configuration.adaptResourceFileNames);
    writeOption(
        ConfigurationConstants.ADAPT_RESOURCE_FILE_CONTENTS_OPTION,
        configuration.adaptResourceFileContents);

    writeOption(ConfigurationConstants.DONT_PREVERIFY_OPTION, !configuration.preverify);
    writeOption(ConfigurationConstants.MICRO_EDITION_OPTION, configuration.microEdition);

    writeOption(ConfigurationConstants.VERBOSE_OPTION, configuration.verbose);
    writeOption(ConfigurationConstants.DONT_NOTE_OPTION, configuration.note, true);
    writeOption(ConfigurationConstants.DONT_WARN_OPTION, configuration.warn, true);
    writeOption(ConfigurationConstants.IGNORE_WARNINGS_OPTION, configuration.ignoreWarnings);
    writeOption(
        ConfigurationConstants.PRINT_CONFIGURATION_OPTION, configuration.printConfiguration);
    writeOption(ConfigurationConstants.DUMP_OPTION, configuration.dump);

    writeOption(ConfigurationConstants.PRINT_SEEDS_OPTION, configuration.printSeeds);
    writer.println();

    // Write the "why are you keeping" options.
    writeOptions(ConfigurationConstants.WHY_ARE_YOU_KEEPING_OPTION, configuration.whyAreYouKeeping);

    // Write the keep options.
    writeOptions(KEEP_OPTIONS, configuration.keep);

    // Write the "no side effect methods" options.
    writeOptions(
        ConfigurationConstants.ASSUME_NO_SIDE_EFFECTS_OPTION, configuration.assumeNoSideEffects);

    if (writer.checkError()) {
      throw new IOException("Can't write configuration");
    }
  }