@@ -67,6 +67,31 @@ void testIO683() throws IOException {
6767 }
6868 }
6969
70+ @ Test
71+ void testPeekDoesNotConsumeBytes () throws IOException {
72+ final byte [] input = "Some" .getBytes (StandardCharsets .UTF_8 );
73+ try (PeekableInputStream inputStream = new PeekableInputStream (new ByteArrayInputStream (input ))) {
74+ assertTrue (inputStream .peek (input ));
75+ assertEquals ('S' , inputStream .read ());
76+ }
77+ }
78+
79+ @ Test
80+ void testPeekExactMatch () throws IOException {
81+ final byte [] input = "Some text buffer" .getBytes (StandardCharsets .UTF_8 );
82+ try (PeekableInputStream inputStream = new PeekableInputStream (new ByteArrayInputStream (input ))) {
83+ assertTrue (inputStream .peek (input ));
84+ }
85+ }
86+
87+ @ Test
88+ void testPeekPrefixDoesNotMatchLongerInput () throws IOException {
89+ try (PeekableInputStream inputStream = new PeekableInputStream (
90+ new ByteArrayInputStream ("Some text buffer" .getBytes (StandardCharsets .UTF_8 )))) {
91+ assertFalse (inputStream .peek ("Some" .getBytes (StandardCharsets .UTF_8 )));
92+ }
93+ }
94+
7095 @ Test
7196 void testRandomRead () throws Exception {
7297 final byte [] inputBuffer = newInputBuffer ();
@@ -102,29 +127,4 @@ void testRandomRead() throws Exception {
102127 }
103128 assertTrue (true , "Test finished OK" );
104129 }
105-
106- @ Test
107- void testPeekExactMatch () throws IOException {
108- final byte [] input = "Some text buffer" .getBytes (StandardCharsets .UTF_8 );
109- try (PeekableInputStream inputStream = new PeekableInputStream (new ByteArrayInputStream (input ))) {
110- assertTrue (inputStream .peek (input ));
111- }
112- }
113-
114- @ Test
115- void testPeekPrefixDoesNotMatchLongerInput () throws IOException {
116- try (PeekableInputStream inputStream = new PeekableInputStream (
117- new ByteArrayInputStream ("Some text buffer" .getBytes (StandardCharsets .UTF_8 )))) {
118- assertFalse (inputStream .peek ("Some" .getBytes (StandardCharsets .UTF_8 )));
119- }
120- }
121-
122- @ Test
123- void testPeekDoesNotConsumeBytes () throws IOException {
124- final byte [] input = "Some" .getBytes (StandardCharsets .UTF_8 );
125- try (PeekableInputStream inputStream = new PeekableInputStream (new ByteArrayInputStream (input ))) {
126- assertTrue (inputStream .peek (input ));
127- assertEquals ('S' , inputStream .read ());
128- }
129- }
130130}
0 commit comments