All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jppf.utils.TexFileSplitter Maven / Gradle / Ivy

There is a newer version: 6.3-alpha
Show newest version
/*
 * JPPF.
 * Copyright (C) 2005-2015 JPPF Team.
 * http://www.jppf.org
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.jppf.utils;

import java.io.*;

/**
 * Utility class that splits a text file into smaller ones with the same number of lines.
 * @author Laurent Cohen
 */
public class TexFileSplitter {
  /**
   * A map of the specified options and their values.
   */
  private static TypedProperties props = new TypedProperties();

  /**
   * Split the input text files into output text files according to the specified options.
   * @param args specifies the options in the format -<option1> <value1> ... -<optionN> <valueN>.
   */
  public static void main(final String[] args) {
    try {
      processArguments(args);
      File file = new File(props.getString("inputFile"));
      int lines = 0;
      String s = "";
      try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
        while (s != null) {
          s = reader.readLine();
          if (s != null) lines++;
        }
      }
      System.out.println("counted " + lines  + " lines");
      try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
        int nbFiles = props.getInt("nbFiles");
        int n = lines/nbFiles;
        for (int i=0; i org.jppf.utils.FileSplitter -option_1 value_1 ... -option_n value_n");
    System.out.println("Available options:");
    System.out.println("  -i input_file             : the path to the text file to split");
    System.out.println("  -o output_dir             : the output directory where to create the resulting files");
    System.out.println("                              no value means same directory as input file");
    System.out.println("  -n nb_files               : number of files to split the input into");
    System.out.println("                              if not specified, 10 is used");
    System.out.println("  -p output_files_prefix    : prefix for the resulting files names");
    System.out.println("  -e output_files_extension : extension for the resulting files names");
    System.out.println("  -?, -h, -help             : display this help screen (all other options are ignored)");
    System.out.println("Examples:");
    System.out.println("java -cp  org.jppf.utils.FileSplitter -i logfile.txt -o ./split -n 5 -p split-log -e .log");
    System.out.println("splits the file logfile.txt into 5, resulting files will be split-log-0.log ... split-log-5.log in folder ./split");
    System.out.println("java -cp  org.jppf.utils.FileSplitter -i logfile.txt");
    System.out.println("splits the file logfile.log into 10, resulting files will be part-0.txt ... part-9.txt in the same folder");
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy