|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| StreamUtils.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Joey and its relative products are published under the terms
|
|
| 3 |
* of the Apache Software License.
|
|
| 4 |
*/
|
|
| 5 |
package org.asyrinx.brownie.core.io;
|
|
| 6 |
|
|
| 7 |
import java.io.BufferedInputStream;
|
|
| 8 |
import java.io.BufferedOutputStream;
|
|
| 9 |
import java.io.BufferedReader;
|
|
| 10 |
import java.io.BufferedWriter;
|
|
| 11 |
import java.io.IOException;
|
|
| 12 |
import java.io.InputStream;
|
|
| 13 |
import java.io.InputStreamReader;
|
|
| 14 |
import java.io.OutputStream;
|
|
| 15 |
import java.io.Reader;
|
|
| 16 |
import java.io.Writer;
|
|
| 17 |
|
|
| 18 |
/**
|
|
| 19 |
* InputStream、OutputStream、Reader、Writerに関するユーティリティクラスです。
|
|
| 20 |
*
|
|
| 21 |
* @author Akima
|
|
| 22 |
*/
|
|
| 23 |
public final class StreamUtils { |
|
| 24 |
|
|
| 25 |
/**
|
|
| 26 |
* Constructor for StreamUtils.
|
|
| 27 |
*/
|
|
| 28 | 0 |
private StreamUtils() {
|
| 29 | 0 |
super();
|
| 30 |
} |
|
| 31 |
|
|
| 32 |
/**
|
|
| 33 |
* 2つReaderで取得した内容が同じかどうかを判断します。
|
|
| 34 |
*
|
|
| 35 |
* @param target1
|
|
| 36 |
* @param target2
|
|
| 37 |
* @return @throws
|
|
| 38 |
* IOException
|
|
| 39 |
*/
|
|
| 40 | 0 |
public static boolean compare(Reader target1, Reader target2) |
| 41 |
throws IOException {
|
|
| 42 | 0 |
int c1 = target1.read();
|
| 43 | 0 |
int c2 = target2.read();
|
| 44 | 0 |
if (c1 != c2)
|
| 45 | 0 |
return false; |
| 46 | 0 |
while ((c1 > -1) && (c2 > -1)) {
|
| 47 | 0 |
c1 = target1.read(); |
| 48 | 0 |
c2 = target2.read(); |
| 49 | 0 |
if (c1 != c2)
|
| 50 | 0 |
return false; |
| 51 |
} |
|
| 52 | 0 |
return true; |
| 53 |
} |
|
| 54 |
|
|
| 55 |
/**
|
|
| 56 |
* 2つInputStreamで取得した内容が同じかどうかを判断します。
|
|
| 57 |
*
|
|
| 58 |
* @param target1
|
|
| 59 |
* @param target2
|
|
| 60 |
* @return @throws
|
|
| 61 |
* IOException
|
|
| 62 |
*/
|
|
| 63 | 0 |
public static boolean compare(InputStream target1, InputStream target2) |
| 64 |
throws IOException {
|
|
| 65 | 0 |
return compare(new InputStreamReader(target1), new InputStreamReader( |
| 66 |
target2)); |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/**
|
|
| 70 |
* sourceから取得した内容をdestにコピーします。
|
|
| 71 |
*
|
|
| 72 |
* @param source
|
|
| 73 |
* @param dest
|
|
| 74 |
* @throws IOException
|
|
| 75 |
*/
|
|
| 76 | 0 |
public static void copy(InputStream source, OutputStream dest) |
| 77 |
throws IOException {
|
|
| 78 | 0 |
copy(source, dest, true);
|
| 79 |
} |
|
| 80 |
|
|
| 81 |
/**
|
|
| 82 |
*
|
|
| 83 |
* sourceから取得した内容をdestにコピーします。
|
|
| 84 |
*
|
|
| 85 |
* @param source
|
|
| 86 |
* @param dest
|
|
| 87 |
* @param buffering
|
|
| 88 |
* trueが指定された場合、sourceとdestそれぞれについてバッファリングします。
|
|
| 89 |
* @throws IOException
|
|
| 90 |
*/
|
|
| 91 | 0 |
public static void copy(InputStream source, OutputStream dest, |
| 92 |
boolean buffering) throws IOException { |
|
| 93 | 0 |
if (buffering) {
|
| 94 | 0 |
source = new BufferedInputStream(source);
|
| 95 | 0 |
dest = new BufferedOutputStream(dest);
|
| 96 |
} |
|
| 97 | 0 |
byte buf[] = new byte[256]; |
| 98 | 0 |
int len;
|
| 99 | 0 |
while ((len = source.read(buf)) != -1) {
|
| 100 | 0 |
dest.write(buf, 0, len); |
| 101 |
} |
|
| 102 | 0 |
dest.flush(); |
| 103 |
} |
|
| 104 |
|
|
| 105 |
/**
|
|
| 106 |
* sourceから取得した内容をdestにコピーします。
|
|
| 107 |
*
|
|
| 108 |
* @param source
|
|
| 109 |
* @param dest
|
|
| 110 |
* @throws IOException
|
|
| 111 |
*/
|
|
| 112 | 0 |
public static void copy(Reader source, Writer dest) throws IOException { |
| 113 | 0 |
copy(source, dest, true);
|
| 114 |
} |
|
| 115 |
|
|
| 116 |
/**
|
|
| 117 |
*
|
|
| 118 |
* sourceから取得した内容をdestにコピーします。
|
|
| 119 |
*
|
|
| 120 |
* @param source
|
|
| 121 |
* @param dest
|
|
| 122 |
* @param buffering
|
|
| 123 |
* trueが指定された場合、sourceとdestそれぞれについてバッファリングします。
|
|
| 124 |
* @throws IOException
|
|
| 125 |
*/
|
|
| 126 | 0 |
public static void copy(Reader source, Writer dest, boolean buffering) |
| 127 |
throws IOException {
|
|
| 128 | 0 |
if (buffering) {
|
| 129 | 0 |
source = new BufferedReader(source);
|
| 130 | 0 |
dest = new BufferedWriter(dest);
|
| 131 |
} |
|
| 132 | 0 |
int c = source.read();
|
| 133 | 0 |
while (c > -1) {
|
| 134 | 0 |
dest.write(c); |
| 135 | 0 |
c = source.read(); |
| 136 |
} |
|
| 137 | 0 |
dest.flush(); |
| 138 |
} |
|
| 139 |
|
|
| 140 |
/**
|
|
| 141 |
* sourceのInputStreamの内容をStringBufferのdestにコピーします。
|
|
| 142 |
*
|
|
| 143 |
* @param source
|
|
| 144 |
* @param dest
|
|
| 145 |
* @throws IOException
|
|
| 146 |
*/
|
|
| 147 | 0 |
public static void copy(InputStream source, StringBuffer dest) |
| 148 |
throws IOException {
|
|
| 149 | 0 |
copy(source, dest, true);
|
| 150 |
} |
|
| 151 |
|
|
| 152 |
/**
|
|
| 153 |
* sourceのInputStreamの内容をStringBufferのdestにコピーします。
|
|
| 154 |
*
|
|
| 155 |
* @param source
|
|
| 156 |
* @param dest
|
|
| 157 |
* @param buffering
|
|
| 158 |
* trueが指定された場合、sourceとdestそれぞれについてバッファリングします。
|
|
| 159 |
* @throws IOException
|
|
| 160 |
*/
|
|
| 161 | 0 |
public static void copy(InputStream source, StringBuffer dest, |
| 162 |
boolean buffering) throws IOException { |
|
| 163 | 0 |
copy(new InputStreamReader(source), dest, buffering);
|
| 164 |
} |
|
| 165 |
|
|
| 166 |
/**
|
|
| 167 |
* sourceのReaderの内容をStringBufferのdestにコピーします。
|
|
| 168 |
*
|
|
| 169 |
* @param source
|
|
| 170 |
* @param dest
|
|
| 171 |
* @throws IOException
|
|
| 172 |
*/
|
|
| 173 | 0 |
public static void copy(Reader source, StringBuffer dest) |
| 174 |
throws IOException {
|
|
| 175 | 0 |
copy(source, dest, true);
|
| 176 |
} |
|
| 177 |
|
|
| 178 |
/**
|
|
| 179 |
* sourceのReaderの内容をStringBufferのdestにコピーします。
|
|
| 180 |
*
|
|
| 181 |
* @param source
|
|
| 182 |
* @param dest
|
|
| 183 |
* @param buffering
|
|
| 184 |
* trueが指定された場合、sourceとdestそれぞれについてバッファリングします。
|
|
| 185 |
* @throws IOException
|
|
| 186 |
*/
|
|
| 187 | 0 |
public static void copy(Reader source, StringBuffer dest, boolean buffering) |
| 188 |
throws IOException {
|
|
| 189 | 0 |
if (buffering) {
|
| 190 | 0 |
source = new BufferedReader(source);
|
| 191 |
} |
|
| 192 | 0 |
int c = source.read();
|
| 193 | 0 |
while (c > -1) {
|
| 194 | 0 |
dest.append((char) c);
|
| 195 | 0 |
c = source.read(); |
| 196 |
} |
|
| 197 |
} |
|
| 198 |
} |
|
||||||||||