@Test public void whenCheckLineWithSpacesThenResultLineWithoutSpaces() { String[] wordFilter = {" ", "goo", "my"}; Abuse abuse = new Abuse(); try (ByteArrayOutputStream output = new ByteArrayOutputStream(); ByteArrayInputStream input = new ByteArrayInputStream("my good little bad son".getBytes())) { abuse.dropAbuses(input, output, wordFilter); assertThat(output.toString(), is("dlittlebadson")); } catch (IOException ioe) { ioe.printStackTrace(); } }
void dropAbuses(InputStream in, OutputStream out, String[] abuse) { StringBuilder sb = new StringBuilder(); boolean isAbusedWord = false; int streamChar; try (InputStreamReader reader = new InputStreamReader(in); OutputStreamWriter writer = new OutputStreamWriter(out)) { while ((streamChar = reader.read()) > 0) { sb.append((char) streamChar); for (String word : abuse) { if (word.startsWith(sb.toString())) { isAbusedWord = true; if (word.equals(sb.toString())) { sb.delete(0, sb.length()); } break; } else { isAbusedWord = false; } } if (!isAbusedWord) { writer.write(sb.toString()); sb.delete(0, sb.length()); } } } catch (IOException ioe) { ioe.printStackTrace(); } }
Abuse { void dropAbuses(InputStream in, OutputStream out, String[] abuse) { StringBuilder sb = new StringBuilder(); boolean isAbusedWord = false; int streamChar; try (InputStreamReader reader = new InputStreamReader(in); OutputStreamWriter writer = new OutputStreamWriter(out)) { while ((streamChar = reader.read()) > 0) { sb.append((char) streamChar); for (String word : abuse) { if (word.startsWith(sb.toString())) { isAbusedWord = true; if (word.equals(sb.toString())) { sb.delete(0, sb.length()); } break; } else { isAbusedWord = false; } } if (!isAbusedWord) { writer.write(sb.toString()); sb.delete(0, sb.length()); } } } catch (IOException ioe) { ioe.printStackTrace(); } } }
Abuse { void dropAbuses(InputStream in, OutputStream out, String[] abuse) { StringBuilder sb = new StringBuilder(); boolean isAbusedWord = false; int streamChar; try (InputStreamReader reader = new InputStreamReader(in); OutputStreamWriter writer = new OutputStreamWriter(out)) { while ((streamChar = reader.read()) > 0) { sb.append((char) streamChar); for (String word : abuse) { if (word.startsWith(sb.toString())) { isAbusedWord = true; if (word.equals(sb.toString())) { sb.delete(0, sb.length()); } break; } else { isAbusedWord = false; } } if (!isAbusedWord) { writer.write(sb.toString()); sb.delete(0, sb.length()); } } } catch (IOException ioe) { ioe.printStackTrace(); } }  }
Abuse { void dropAbuses(InputStream in, OutputStream out, String[] abuse) { StringBuilder sb = new StringBuilder(); boolean isAbusedWord = false; int streamChar; try (InputStreamReader reader = new InputStreamReader(in); OutputStreamWriter writer = new OutputStreamWriter(out)) { while ((streamChar = reader.read()) > 0) { sb.append((char) streamChar); for (String word : abuse) { if (word.startsWith(sb.toString())) { isAbusedWord = true; if (word.equals(sb.toString())) { sb.delete(0, sb.length()); } break; } else { isAbusedWord = false; } } if (!isAbusedWord) { writer.write(sb.toString()); sb.delete(0, sb.length()); } } } catch (IOException ioe) { ioe.printStackTrace(); } }   }
Abuse { void dropAbuses(InputStream in, OutputStream out, String[] abuse) { StringBuilder sb = new StringBuilder(); boolean isAbusedWord = false; int streamChar; try (InputStreamReader reader = new InputStreamReader(in); OutputStreamWriter writer = new OutputStreamWriter(out)) { while ((streamChar = reader.read()) > 0) { sb.append((char) streamChar); for (String word : abuse) { if (word.startsWith(sb.toString())) { isAbusedWord = true; if (word.equals(sb.toString())) { sb.delete(0, sb.length()); } break; } else { isAbusedWord = false; } } if (!isAbusedWord) { writer.write(sb.toString()); sb.delete(0, sb.length()); } } } catch (IOException ioe) { ioe.printStackTrace(); } }    }