};
}
+ public static Matcher<InputStream> equalTo(byte... content) {
+ return new TypeSafeDiagnosingMatcher<InputStream>() {
+ @Override
+ protected boolean matchesSafely(InputStream inputStream, Description mismatchDescription) {
+ try {
+ for (int index = 0; index < content.length; index++) {
+ int readByte = inputStream.read();
+ if ((readByte == -1) || ((byte) readByte != content[index])) {
+ mismatchDescription.appendText("was ").appendValue(readByte).appendText(" at offset ").appendValue(index);
+ return false;
+ }
+ }
+ int eof = inputStream.read();
+ if (eof != -1) {
+ mismatchDescription.appendText("contained more than ").appendValue(content.length).appendText(" bytes");
+ return false;
+ }
+ } catch (IOException e) {
+ mismatchDescription.appendText("could not be read (").appendValue(e).appendText(")");
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public void describeTo(Description description) {
+ description.appendText("is input stream containing ").appendValue(content);
+ }
+ };
+ }
+
}