package com.greensnow25;

import java.io.*;

/**
 * public class RemovalOfBannedWords removes the forbidden words in a stream .
 *
 * @author grensnow25.
 * @version 1.
 * @since 13.02.17.
 */
public class RemovalOfBannedWords {

    private String[] abuse = new String[]{"hello", "world"};

    void dropAbuses(InputStream in, OutputStream out, String[] words) {
        String test = "I wrote a program hello world well";
        try (BufferedReader brIn = new BufferedReader(new InputStreamReader(in));
             BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out))) {
            String line = brIn.readLine();
            String[] res = checkAbuse(line, words);

            for (String wellWords : res) {
                bw.write(wellWords + " ");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public String[] checkAbuse(String line, String[] abuse) {
        String[] lineWords = line.split(" ");
        int position = 0;
        for (int i = 0; i != lineWords.length; i++) {
            for (int j = 0; j != abuse.length; j++) {
                if (lineWords[i] != null && abuse[j] != null && lineWords[i].equals(abuse[j])) {
                    lineWords[i] = null;
                    position++;
                }
            }
        }
        String[] lineWithOutAbuse = new String[lineWords.length - position];
        int count = 0;
        for (int i = 0; i != lineWords.length; i++) {
            if (lineWords[i] != null) {
                lineWithOutAbuse[count++] = lineWords[i];
            }
        }
        return lineWithOutAbuse;
    }
}

@@ -222,16 +222,52 @@
 Words %7B%0A
+    /**%0A     * abuses words.%0A     */
 %0A    pri
@@ -321,16 +321,207 @@
 rld%22%7D;%0A%0A
+    /**%0A     * method creates an input and output streams, reads and displays the message.%0A     * @param in stream in.%0A     * @param out stream out.%0A     * @param words abuses words.%0A     */%0A
     void
@@ -1090,16 +1090,182 @@
 %0A    %7D%0A%0A
+    /**%0A     *method removes the bad words.%0A     * @param line input string.%0A     * @param abuse array of bad words.%0A     * @return array with out bad words.%0A     */%0A
     publ

Update date 15.02.17