import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Copies a file containing JavaFX color names and the corresponding RGB values to a new
 * file containing just the names.
 *
 * Using low-level byte streams for demonstration.
 *
 * @author Drue Coles
 */
public class ColorCopy {

    public static void main(String[] args) throws IOException {

        FileInputStream input = null;
        FileOutputStream output = null;
        String inFileName = "colors.txt";
        String outFileName = "output.txt";
        
        try {
            input = new FileInputStream(inFileName);
            output = new FileOutputStream(outFileName);

            int byteVal;
            boolean readingUpperCaseLetter = true;
            while ((byteVal = input.read()) != -1) {

                if (Character.isUpperCase(byteVal)) {

                    // If not previously reading an uppercase letter, then this is the
                    // start of a new color name, so output a newline character.
                    if (!readingUpperCaseLetter) {
                        output.write('\n');
                        readingUpperCaseLetter = true;
                    }

                    // The current byte is an uppercase letter so it is part of a color 
                    // name and is written to the output.
                    output.write(byteVal);
                } else {
                    readingUpperCaseLetter = false;
                }
            }
        } catch (FileNotFoundException e) {
            System.out.printf("Could not find %s in working directory.%n", inFileName);
        } finally {
            if (input != null) {
                input.close();
            }
            if (output != null) {
                output.close();
            }
        }
    }
}