ストリームコピー用のコードがあります。
OutputStream os = ...;
InputStream is = ...;
int bufferLength;
byte[] buffer = new byte[1024];
while ((bufferLength = is.read(buffer)) != -1) {
os.write(buffer, 0, bufferLength);
}
その上で PMD を実行すると、http://pmd.sourceforge.net/rules/controversial.html#AssignmentInOperandという警告が表示されます。
今、私はその警告を取り除きたいと思っていますが、私が考えることができる唯一の代替手段は次のようなものです
OutputStream os = ...;
InputStream is = ...;
int bufferLength;
byte[] buffer = new byte[1024];
bufferLength = is.read(buffer);
while (bufferLength != -1) {
os.write(buffer, 0, bufferLength);
bufferLength = is.read(buffer);
}
コードを複製することになるので、私はそれがあまり好きではありません。この PMD ルールを満たすためのよりエレガントな方法はありますか?