Skip to content

Commit 510a488

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 <[email protected]>
1 parent 865edaf commit 510a488

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;
@@ -730,4 +731,26 @@ private static void getSurefireBooterURLs(final File file, final URL baseURL,
730731
}
731732
}
732733

734+
/**
735+
* Read complete contents of a Reader and return as String.
736+
*
737+
* @param reader {@link Reader} whose output should be returned as String.
738+
* @return contents of reader as String.
739+
*/
740+
private static String getReaderContentsAsString(Reader reader) throws IOException {
741+
if (reader == null) {
742+
return null;
743+
}
744+
745+
CharBuffer buffer = CharBuffer.allocate(1024);
746+
StringBuilder builder = new StringBuilder();
747+
748+
int read;
749+
while ((read = reader.read(buffer)) != -1) {
750+
builder.append(buffer, 0, read);
751+
}
752+
753+
return builder.toString();
754+
}
755+
733756
}

0 commit comments

Comments
 (0)