diff options
author | Evgeny Astigeevich <evgeny.astigeevich@linaro.org> | 2019-08-06 15:07:14 +0100 |
---|---|---|
committer | Evgeny Astigeevich <evgeny.astigeevich@linaro.org> | 2019-08-23 11:51:44 +0000 |
commit | c3f4acca9caf04ef8788355c2be11a3a68ace5ad (patch) | |
tree | 5a35de1ae4e33a3f516722c88cde1cc309ff0032 | |
parent | 5e5566a0483d6e58b5ac1725f992759a64f3cf85 (diff) | |
download | art-testing-c3f4acca9caf04ef8788355c2be11a3a68ace5ad.tar.gz |
Add NullOutputStream and readDataFromFile
Some benchmarks need some kind of /dev/null output stream. Some others
need to read data from a file.
This CL adds implementations of NullOutputStream and readDataFromFile as
Util.java.
Test: benchmarks_run_target.sh --iterations 1
Change-Id: I7f647d737386553c442493394088b0d38b4d70ea
-rw-r--r-- | framework/org/linaro/bench/Util.java | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/framework/org/linaro/bench/Util.java b/framework/org/linaro/bench/Util.java new file mode 100644 index 0000000..66ce1a6 --- /dev/null +++ b/framework/org/linaro/bench/Util.java @@ -0,0 +1,54 @@ +/* + * Copyright 2019 Linaro Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package org.linaro.bench; + +import java.io.ByteArrayOutputStream; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.OutputStream; + +public class Util { + public static final class NullOutputStream extends OutputStream { + @Override + public void write(int b) throws IOException { + // Writes to nowhere + } + } + + public static String readDataFromFile(final String fileName) { + BufferedReader in = null; + try { + try { + in = new BufferedReader(new FileReader(fileName)); + StringBuilder strBuilder = new StringBuilder(in.readLine()); + String line; + while ((line = in.readLine()) != null) { + strBuilder.append('\n').append(line); + } + return strBuilder.toString(); + } finally { + if (in != null) { + in.close(); + } + } + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} |