@Test public void testStripHeader2() throws Exception { final String withHeader = "#version 440\n" + " + " + "\n\n\n" + " + "void main()\n" + "{\n" + "}\n"; final String expected = "#version 440\n" + "void main()\n" + "{\n" + "}\n"; final InputStream is = new ByteArrayInputStream(withHeader.getBytes(StandardCharsets.UTF_8)); final InputStream strippedIs = ParseHelper.stripGraphicsFuzzDefines(is); assertNotSame(is, strippedIs); assertEquals(expected, getStringFromInputStream(strippedIs)); }
static InputStream stripGraphicsFuzzDefines(InputStream inputStream) throws IOException { if (!containsEndOfGraphicsFuzzDefines(inputStream)) { return inputStream; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try ( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { boolean passedEndOfGraphicsFuzzDefines = false; String line; while ((line = br.readLine()) != null) { if (passedEndOfGraphicsFuzzDefines || isVersion(line) || ShadingLanguageVersion.isWebGlHint(line)) { bw.write(line + "\n"); } else { if (line.trim().startsWith(END_OF_GRAPHICSFUZZ_DEFINES)) { passedEndOfGraphicsFuzzDefines = true; } } } } byte[] fileContents = outputStream.toByteArray(); return new ByteArrayInputStream(fileContents); }
ParseHelper { static InputStream stripGraphicsFuzzDefines(InputStream inputStream) throws IOException { if (!containsEndOfGraphicsFuzzDefines(inputStream)) { return inputStream; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try ( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { boolean passedEndOfGraphicsFuzzDefines = false; String line; while ((line = br.readLine()) != null) { if (passedEndOfGraphicsFuzzDefines || isVersion(line) || ShadingLanguageVersion.isWebGlHint(line)) { bw.write(line + "\n"); } else { if (line.trim().startsWith(END_OF_GRAPHICSFUZZ_DEFINES)) { passedEndOfGraphicsFuzzDefines = true; } } } } byte[] fileContents = outputStream.toByteArray(); return new ByteArrayInputStream(fileContents); } }
ParseHelper { static InputStream stripGraphicsFuzzDefines(InputStream inputStream) throws IOException { if (!containsEndOfGraphicsFuzzDefines(inputStream)) { return inputStream; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try ( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { boolean passedEndOfGraphicsFuzzDefines = false; String line; while ((line = br.readLine()) != null) { if (passedEndOfGraphicsFuzzDefines || isVersion(line) || ShadingLanguageVersion.isWebGlHint(line)) { bw.write(line + "\n"); } else { if (line.trim().startsWith(END_OF_GRAPHICSFUZZ_DEFINES)) { passedEndOfGraphicsFuzzDefines = true; } } } } byte[] fileContents = outputStream.toByteArray(); return new ByteArrayInputStream(fileContents); }  }
ParseHelper { static InputStream stripGraphicsFuzzDefines(InputStream inputStream) throws IOException { if (!containsEndOfGraphicsFuzzDefines(inputStream)) { return inputStream; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try ( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { boolean passedEndOfGraphicsFuzzDefines = false; String line; while ((line = br.readLine()) != null) { if (passedEndOfGraphicsFuzzDefines || isVersion(line) || ShadingLanguageVersion.isWebGlHint(line)) { bw.write(line + "\n"); } else { if (line.trim().startsWith(END_OF_GRAPHICSFUZZ_DEFINES)) { passedEndOfGraphicsFuzzDefines = true; } } } } byte[] fileContents = outputStream.toByteArray(); return new ByteArrayInputStream(fileContents); }  static Optional<TranslationUnit> maybeParseShader(File shader); static synchronized TranslationUnit parse(File file); static synchronized TranslationUnit parse(String string, ShaderKind shaderKind); static synchronized TranslationUnit parse(String string); }
ParseHelper { static InputStream stripGraphicsFuzzDefines(InputStream inputStream) throws IOException { if (!containsEndOfGraphicsFuzzDefines(inputStream)) { return inputStream; } ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try ( BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(outputStream)); BufferedReader br = new BufferedReader(new InputStreamReader(inputStream))) { boolean passedEndOfGraphicsFuzzDefines = false; String line; while ((line = br.readLine()) != null) { if (passedEndOfGraphicsFuzzDefines || isVersion(line) || ShadingLanguageVersion.isWebGlHint(line)) { bw.write(line + "\n"); } else { if (line.trim().startsWith(END_OF_GRAPHICSFUZZ_DEFINES)) { passedEndOfGraphicsFuzzDefines = true; } } } } byte[] fileContents = outputStream.toByteArray(); return new ByteArrayInputStream(fileContents); }  static Optional<TranslationUnit> maybeParseShader(File shader); static synchronized TranslationUnit parse(File file); static synchronized TranslationUnit parse(String string, ShaderKind shaderKind); static synchronized TranslationUnit parse(String string); static final String END_OF_GRAPHICSFUZZ_DEFINES; }