2
* Licensed to the Apache Software Foundation (ASF) under one or more
3
* contributor license agreements. See the NOTICE file distributed with
4
* this work for additional information regarding copyright ownership.
5
* The ASF licenses this file to You under the Apache License, Version 2.0
6
* (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
18
package org.apache.commons.compress.utils;
20
import java.io.ByteArrayInputStream;
21
import java.io.FilterInputStream;
22
import java.io.InputStream;
23
import java.io.IOException;
25
import org.junit.Assert;
26
import org.junit.Test;
28
public class IOUtilsTest {
30
private interface StreamWrapper {
31
InputStream wrap(InputStream toWrap);
35
public void skipUsingSkip() throws Exception {
36
skip(new StreamWrapper() {
37
public InputStream wrap(InputStream toWrap) {
44
public void skipUsingRead() throws Exception {
45
skip(new StreamWrapper() {
46
public InputStream wrap(InputStream toWrap) {
47
return new FilterInputStream(toWrap) {
48
public long skip(long s) {
57
public void skipUsingSkipAndRead() throws Exception {
58
skip(new StreamWrapper() {
59
public InputStream wrap(final InputStream toWrap) {
60
return new FilterInputStream(toWrap) {
62
public long skip(long s) throws IOException {
75
private void skip(StreamWrapper wrapper) throws Exception {
76
ByteArrayInputStream in = new ByteArrayInputStream(new byte[] {
77
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11
79
InputStream sut = wrapper.wrap(in);
80
Assert.assertEquals(10, IOUtils.skip(sut, 10));
81
Assert.assertEquals(11, sut.read());