Skip to content

Commit b1362ea

Browse files
committed
Add utility method for getting Reader contents as String
Needed in future recompilation avoidance for hash calculation. TODO: Move to a utility class? Signed-off-by: Squareys <Squareys@googlemail.com>
1 parent 6ed6216 commit b1362ea

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import java.net.MalformedURLException;
4747
import java.net.URL;
4848
import java.net.URLClassLoader;
49+
import java.nio.CharBuffer;
4950
import java.util.ArrayList;
5051
import java.util.List;
5152
import java.util.jar.JarFile;
@@ -755,4 +756,26 @@ private static void getSurefireBooterURLs(final File file, final URL baseURL,
755756
}
756757
}
757758

759+
/**
760+
* Read complete contents of a Reader and return as String.
761+
*
762+
* @param reader {@link Reader} whose output should be returned as String.
763+
* @return contents of reader as String.
764+
*/
765+
private static String getReaderContentsAsString(Reader reader) throws IOException {
766+
if (reader == null) {
767+
return null;
768+
}
769+
770+
CharBuffer buffer = CharBuffer.allocate(1024);
771+
StringBuilder builder = new StringBuilder();
772+
773+
int read;
774+
while ((read = reader.read(buffer)) != -1) {
775+
builder.append(buffer, 0, read);
776+
}
777+
778+
return builder.toString();
779+
}
780+
758781
}

0 commit comments

Comments
 (0)