// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
//     final byte[][] holder = new byte[1][];
//     final ByteOutput output = new ArrayByteOutput(null) {
//         @Override
//         public void write(int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(holder[0] = new byte[1]);
//                 setIndex(0);
//             }
//             final byte[] target = getTarget();
//             if (getIndex() == target.length) {
//                 setTarget(copyOf(target, target.length << 1));
//                 holder[0] = getTarget();
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new ArrayByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
//                 setIndex(0);
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
//     final ByteBuffer[] holder = new ByteBuffer[1];
//     final ByteOutput output = new BufferByteOutput(null) {
//         @Override
//         public void write(int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(holder[0] = allocate(1));
//             }
//             final ByteBuffer target = getTarget();
//             if (!target.hasRemaining()) {
//                 final ByteBuffer bigger = allocate(target.capacity() << 1);
//                 if (target.hasArray() && bigger.hasArray()) {
//                     arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
//                               target.position());
//                     bigger.position(target.position());
//                 } else {
//                     for (target.flip(); target.hasRemaining(); ) {
//                         bigger.put(target.get());
//                     }
//                 }
//                 setTarget(bigger);
//                 holder[0] = getTarget();
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new BufferByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
//                 ((Buffer) getSource()).flip(); // limit -> position, position -> zero
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
//     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//     final ByteOutput output = new DataByteOutput(null) {
//         @Override
//         public void write(final int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(new DataOutputStream(baos));
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new DataByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
//     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//     final ByteOutput output = new StreamByteOutput(null) {
//         @Override
//         public void write(final int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(baos);
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new StreamByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(new ByteArrayInputStream(baos.toByteArray()));
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }


import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData;
package com.github.jinahya.bit.io;

/*-
 * #%L
 * bit-io
 * %%
 * Copyright (C) 2014 - 2019 Jinahya, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * A class for sourcing {@link BitInput} and {@link BitOutput}.
 *
 * @author Jin Kwon &lt;onacit_at_gmail.com&gt;
 */
@Slf4j
final class BitIoSource {

    // -----------------------------------------------------------------------------------------------------------------

    /**
     * Sources arguments of {@link BitOutput} and {@link BitInput}.
     *
     * @return a stream of arguments
     * @see ByteIoSource#sourceByteIoArray()
     */
    static Stream<Arguments> sourceBitIoArray() {
        return sourceByteIoArray().map(a -> {
            final ArgumentsAccessor accessor = new DefaultArgumentsAccessor(a.get());
            return Arguments.of(new DefaultBitOutput(accessor.get(0, ByteOutput.class)),
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoArray() {
//     final byte[][] holder = new byte[1][];
//     final ByteOutput output = new ArrayByteOutput(null) {
//         @Override
//         public void write(int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(holder[0] = new byte[1]);
//                 setIndex(0);
//             }
//             final byte[] target = getTarget();
//             if (getIndex() == target.length) {
//                 setTarget(copyOf(target, target.length << 1));
//                 holder[0] = getTarget();
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new ArrayByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(ofNullable(holder[0]).orElseGet(() -> new byte[0]));
//                 setIndex(0);
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoBuffer() {
//     final ByteBuffer[] holder = new ByteBuffer[1];
//     final ByteOutput output = new BufferByteOutput(null) {
//         @Override
//         public void write(int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(holder[0] = allocate(1));
//             }
//             final ByteBuffer target = getTarget();
//             if (!target.hasRemaining()) {
//                 final ByteBuffer bigger = allocate(target.capacity() << 1);
//                 if (target.hasArray() && bigger.hasArray()) {
//                     arraycopy(target.array(), target.arrayOffset(), bigger.array(), target.arrayOffset(),
//                               target.position());
//                     bigger.position(target.position());
//                 } else {
//                     for (target.flip(); target.hasRemaining(); ) {
//                         bigger.put(target.get());
//                     }
//                 }
//                 setTarget(bigger);
//                 holder[0] = getTarget();
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new BufferByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(ofNullable(holder[0]).orElseGet(() -> allocate(0)));
//                 ((Buffer) getSource()).flip(); // limit -> position, position -> zero
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoData() {
//     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//     final ByteOutput output = new DataByteOutput(null) {
//         @Override
//         public void write(final int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(new DataOutputStream(baos));
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new DataByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(new DataInputStream(new ByteArrayInputStream(baos.toByteArray())));
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }
// 
// Path: src/test/java/com/github/jinahya/bit/io/ByteIoSource.java
// static Stream<Arguments> sourceByteIoStream() {
//     final ByteArrayOutputStream baos = new ByteArrayOutputStream();
//     final ByteOutput output = new StreamByteOutput(null) {
//         @Override
//         public void write(final int value) throws IOException {
//             if (getTarget() == null) {
//                 setTarget(baos);
//             }
//             super.write(value);
//         }
//     };
//     final ByteInput input = new StreamByteInput(null) {
//         @Override
//         public int read() throws IOException {
//             if (getSource() == null) {
//                 setSource(new ByteArrayInputStream(baos.toByteArray()));
//             }
//             return super.read();
//         }
//     };
//     return Stream.of(Arguments.of(output, input));
// }


// Path: src/test/java/com/github/jinahya/bit/io/BitIoSource.java
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoStream;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.params.aggregator.ArgumentsAccessor;
import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor;
import org.junit.jupiter.params.provider.Arguments;
import java.util.stream.Stream;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoArray;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoBuffer;
import static com.github.jinahya.bit.io.ByteIoSource.sourceByteIoData;

package com.github.jinahya.bit.io;

/*-
 * #%L
 * bit-io
 * %%
 * Copyright (C) 2014 - 2019 Jinahya, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */




/**
 * A class for sourcing {@link BitInput} and {@link BitOutput}.
 *
 * @author Jin Kwon &lt;onacit_at_gmail.com&gt;
 */
@Slf4j
final class BitIoSource {

    // -----------------------------------------------------------------------------------------------------------------

    /**
     * Sources arguments of {@link BitOutput} and {@link BitInput}.
     *
     * @return a stream of arguments
     * @see ByteIoSource#sourceByteIoArray()
     */
    static Stream<Arguments> sourceBitIoArray() {
        return sourceByteIoArray().map(a -> {
            final ArgumentsAccessor accessor = new DefaultArgumentsAccessor(a.get());
            return Arguments.of(new DefaultBitOutput(accessor.get(0, ByteOutput.class)),
                                new DefaultBitInput(accessor.get(1, ByteInput.class)));