Ejemplo n.º 1
0
  @Override
  public String load(File file) throws IOException {
    if (file == null) throw new IllegalArgumentException();

    FileReader reader = new FileReader(file);
    char[] c = new char[4096];

    if (reader.ready()) reader.read(c);

    reader.close();

    return new String(c);
  }
Ejemplo n.º 2
0
 public static void main(String[] args) throws IOException {
   BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
   FileReader fileReader = new FileReader(reader.readLine());
   FileWriter fileWriter = new FileWriter(reader.readLine());
   StringBuilder text = new StringBuilder("");
   while (fileReader.ready()) {
     int c = fileReader.read();
     String str = String.valueOf((char) c);
     if (!str.matches("\\p{Punct}")) {
       text.append(str);
     }
   }
   fileWriter.write(text.toString());
   fileReader.close();
   fileWriter.close();
   reader.close();
 }
Ejemplo n.º 3
0
 public static String open(String fileName) {
   String resultat = new String("");
   try {
     File file = new File(fileName);
     int size = (int) file.length();
     int chars_read = 0;
     FileReader in = new FileReader(file);
     char[] data = new char[size];
     while (in.ready()) {
       chars_read += in.read(data, chars_read, size - chars_read);
     }
     resultat = new String(data, 0, chars_read);
     in.close();
   } catch (IOException e) {
     String f =
         fileName.replace(net.ko.utils.KApplication.getRootPath(KClassCreator.class) + "/", "");
     resultat = openRessource(f);
   }
   return resultat;
 }
Ejemplo n.º 4
0
  public static ServerModel getServer() {
    ServerModel model = new ServerModel();
    String server = new String();
    try {
      FileReader fr = new FileReader("input/server.ser");
      BufferedReader input = new BufferedReader(fr);
      if (!fr.ready()) {
        model.setDataname(null);
        model.setHostname(null);
        model.setPassword(null);
        model.setUsername(null);
      } else {
        server =
            ServerUtil.deencryptionStr(
                input.readLine()); // StringUtil.decriptString(input.readLine());
        try {
          if (server != null && !server.equals("")) {
            String[] array = server.split(",");
            String host = array[0].substring(0, array[0].length() - 13);
            ;
            model.setHostname(host);
            String data = array[1].substring(0, array[1].length() - 15);
            model.setDataname(data);
            String user = array[2].substring(0, array[2].length() - 15);
            model.setUsername(user);
            String pass = array[3].substring(0, array[3].length() - 9);
            model.setPassword(pass);
          }
        } catch (Exception e) {
          e.printStackTrace();
          JOptionPane.showMessageDialog(null, e.getMessage());
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
      JOptionPane.showMessageDialog(null, "Not found file server! Please configure server!");
    }

    return model;
  }
Ejemplo n.º 5
0
  public static void main(String[] args) {

    WikiPageController wpc = new WikiPageController();

    String page = "foo";

    StringBuilder originalText = new StringBuilder();
    try {
      FileReader fr = new FileReader("textMarkup.fscode.xml");
      while (fr.ready()) originalText.append((char) fr.read());
    } catch (FileNotFoundException ex) {
      Logger.getLogger(MakeStuffPersistTest.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException e) {

    }

    wpc.setPageMarkup(page, new String(originalText.toString()));

    String markup = wpc.getPageMarkup(page);

    if (!markup.equalsIgnoreCase(originalText.toString())) {
      System.out.println("======= MAJOR PROBLEM, APPARENTLY THE DB IS MANGLING THE TEXT!!!");
      if (markup.length() != originalText.length()) {
        System.out.println(
            "markup.length = "
                + markup.length()
                + "\noriginaltext.length = "
                + originalText.length());
      }
    }

    System.out.println("========= MARKUP =========");
    System.out.println(markup);

    System.out.println("========== HTML ==========");
    System.out.println(wpc.getPageHtml(page));
  }
Ejemplo n.º 6
0
  public static void main(String... args) throws IOException {

    HashMap<Option, String> options = new HashMap<Option, String>();
    LinkedList<String> others = new LinkedList<String>();

    for (Option option : Option.values())
      if (option.defaultValue != null) options.put(option, option.defaultValue);

    if (args != null && args.length > 0) {
      Pattern valueGetter = Pattern.compile("^--\\w[\\w-]*\\w?(?:=(?:\"([^\"]*)\"|([^\\s]*)))$");

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

        if (args[i].matches("^--\\w[\\w-]*\\w?(=(\"[^\"]*\"|[^\\s]*))?$")) {
          boolean found = false;
          for (Option option : Option.values()) {
            if (args[i].startsWith("--" + option.fullopts + "=")) {
              Matcher m = valueGetter.matcher(args[i]);

              if (m.matches()) {
                options.put(option, m.group(1) == null ? m.group(2) : m.group(1));
              }

              found = true;
              break;
            }
          }

          if (!found) {
            System.err.printf("unknown option: %s%n", args[i].substring(0, args[i].indexOf('=')));
            System.exit(1);
          }
        } else if (args[i].matches("^-\\w$")) {
          boolean found = false;

          for (Option option : Option.values()) {
            if (args[i].equals("-" + option.shortopts)) {
              options.put(option, args[++i]);
              break;
            }
          }

          if (!found) {
            System.err.printf("unknown option: %s%n", args[i]);
            System.exit(1);
          }
        } else {
          others.addLast(args[i]);
        }
      }
    } else {
      usage();
      System.exit(0);
    }

    LinkedList<String> errors = new LinkedList<String>();

    if (others.size() == 0) {
      errors.add("dgs file name missing.");
    }

    String imagePrefix;
    OutputType outputType = null;
    OutputPolicy outputPolicy = null;
    Resolution resolution = null;
    Quality quality = null;
    String logo;
    String stylesheet;

    imagePrefix = options.get(Option.IMAGE_PREFIX);

    try {
      outputType = OutputType.valueOf(options.get(Option.IMAGE_TYPE));
    } catch (IllegalArgumentException e) {
      errors.add("bad image type: " + options.get(Option.IMAGE_TYPE));
    }

    try {
      outputPolicy = OutputPolicy.valueOf(options.get(Option.OUTPUT_POLICY));
    } catch (IllegalArgumentException e) {
      errors.add("bad output policy: " + options.get(Option.OUTPUT_POLICY));
    }

    try {
      quality = Quality.valueOf(options.get(Option.QUALITY));
    } catch (IllegalArgumentException e) {
      errors.add("bad quality: " + options.get(Option.QUALITY));
    }

    logo = options.get(Option.LOGO);
    stylesheet = options.get(Option.STYLESHEET);

    try {
      resolution = Resolutions.valueOf(options.get(Option.IMAGE_RESOLUTION));
    } catch (IllegalArgumentException e) {
      Pattern p = Pattern.compile("^\\s*(\\d+)\\s*x\\s*(\\d+)\\s*$");
      Matcher m = p.matcher(options.get(Option.IMAGE_RESOLUTION));

      if (m.matches()) {
        resolution =
            new CustomResolution(Integer.parseInt(m.group(1)), Integer.parseInt(m.group(2)));
      } else {
        errors.add("bad resolution: " + options.get(Option.IMAGE_RESOLUTION));
      }
    }

    if (stylesheet != null && stylesheet.length() < 1024) {
      File test = new File(stylesheet);

      if (test.exists()) {
        FileReader in = new FileReader(test);
        char[] buffer = new char[128];
        String content = "";

        while (in.ready()) {
          int c = in.read(buffer, 0, 128);
          content += new String(buffer, 0, c);
        }

        stylesheet = content;
        in.close();
      }
    }

    {
      File test = new File(others.peek());
      if (!test.exists()) errors.add(String.format("file \"%s\" does not exist", others.peek()));
    }

    if (errors.size() > 0) {
      System.err.printf("error:%n");

      for (String error : errors) System.err.printf("- %s%n", error);

      System.exit(1);
    }

    FileSourceDGS dgs = new FileSourceDGS();
    FileSinkImages fsi = new FileSinkImages(imagePrefix, outputType, resolution, outputPolicy);

    dgs.addSink(fsi);

    if (logo != null) fsi.addLogo(logo, 0, 0);

    fsi.setQuality(quality);
    if (stylesheet != null) fsi.setStyleSheet(stylesheet);

    boolean next = true;

    dgs.begin(others.get(0));

    while (next) next = dgs.nextStep();

    dgs.end();
  }