Move logic to write to stdout into CodeWriter
This will allow us to reuse it when we write C++ code.
I think this will mostly come in handy for debugging.
While here, rename the helper functions in accordance with the style
guide.
Test: unittests
Bug: 24220933
Change-Id: I269eb4a0dda10588c2ae77b7c8f2b00e50e70047
diff --git a/generate_java.cpp b/generate_java.cpp
index 5626d3d..868783c 100644
--- a/generate_java.cpp
+++ b/generate_java.cpp
@@ -78,22 +78,7 @@
document->originalSrc = originalSrc;
document->classes.push_back(cl);
-// printf("outputting... filename=%s\n", filename.c_str());
- FILE* to;
- if (filename == "-") {
- to = stdout;
- } else {
- /* open file in binary mode to ensure that the tool produces the
- * same output on all platforms !!
- */
- to = fopen(filename.c_str(), "wb");
- if (to == NULL) {
- fprintf(stderr, "unable to open %s for write\n", filename.c_str());
- return 1;
- }
- }
-
- CodeWriterPtr code_writer = get_file_writer(to);
+ CodeWriterPtr code_writer = GetFileWriter(filename);
document->Write(code_writer.get());
return 0;