Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.sincore.tools.asc;
- import java.io.*;
- import java.util.Scanner;
- /**
- * Create user: lh
- * Create date: 10/24/11 / 11:32 AM
- */
- public class Main
- {
- public static String fromAdcString(String adcString)
- {
- if (adcString == null)
- return null;
- return adcString.replaceAll("\\\\s", " ")
- .replaceAll("\\\\n", "\n")
- .replaceAll("\\\\\\\\", "\\\\")
- .replaceAll("\\\\ ", "\\\\s")
- .replaceAll("\\\\\\n", "\\\\n");
- }
- /**
- * @param args the command line arguments (Not used)
- */
- public static void main(String[] args)
- {
- System.out.println("Achtung! Application started!");
- if (args.length < 1)
- {
- System.out.println("Usage: asc <input filename> [<output filename>]");
- System.out.println("\t Where <input filename> is a name of file with normal text,");
- System.out.println("\t and <output filename> is a name of output file with adc compatible text.");
- return;
- }
- else
- {
- String outputFileName = args.length == 2 ? args[1] : "adc_" + args[0];
- try
- {
- File file = new File(outputFileName);
- if (!file.exists())
- {
- System.out.println("File doesn't exists. Creating new...");
- if (!file.createNewFile())
- {
- System.out.println("Error! File cannot be created.");
- return;
- }
- }
- Scanner scanner = new Scanner(new FileInputStream(args[0]), "UTF-8");
- FileOutputStream fos = new FileOutputStream(outputFileName);
- OutputStreamWriter out = new OutputStreamWriter(fos);
- int charBuffer;
- int offset = 0;
- StringBuilder text = new StringBuilder();
- while (scanner.hasNextLine())
- {
- text.append(scanner.nextLine());
- }
- out.write(toAdcString(text.toString()));
- scanner.close();
- out.close();
- }
- catch (FileNotFoundException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment