<commit_before>/*
 ** 2014 February 24
 **
 ** The author disclaims copyright to this source code.  In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.io.socket;

import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class ChannelSocket extends IOSocket {
    
    public ChannelSocket(ReadableByteChannel chan) {
        setRawReadableByteChannel(chan);
        setCanRead(true);
    }
    
    public ChannelSocket(WritableByteChannel chan) {
        setRawWritableByteChannel(chan);
        setCanWrite(true);
    }
}
<commit_msg>Improved ChannelSocket constructor<commit_after>/*
 ** 2014 February 24
 **
 ** The author disclaims copyright to this source code.  In place of
 ** a legal notice, here is a blessing:
 **    May you do good and not evil.
 **    May you find forgiveness for yourself and forgive others.
 **    May you share freely, never taking more than you give.
 */
package info.ata4.io.socket;

import info.ata4.io.SeekableImpl;
import java.io.IOException;
import java.nio.channels.Channel;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.SeekableByteChannel;
import java.nio.channels.WritableByteChannel;

/**
 *
 * @author <NAME> <barracuda415 at yahoo.de>
 */
public class ChannelSocket extends IOSocket {
    
    public ChannelSocket(Channel channel) {
        if (channel instanceof ReadableByteChannel) {
            setRawReadableByteChannel((ReadableByteChannel) channel);
            setCanRead(true);
        }
        
        if (channel instanceof WritableByteChannel) {
            setRawWritableByteChannel((WritableByteChannel) channel);
            setCanWrite(true);
        }
        
        if (channel instanceof SeekableByteChannel) {
            setSeekable(new ChannelSeekable((SeekableByteChannel) channel));
        }
    }
    
    private class ChannelSeekable extends SeekableImpl {
        
        private final SeekableByteChannel channel;
        
        private ChannelSeekable(SeekableByteChannel channel) {
            this.channel = channel;
        }

        @Override
        public void position(long where) throws IOException {
            channel.position(where);
        }

        @Override
        public long position() throws IOException {
            return channel.position();
        }

        @Override
        public long capacity() throws IOException {
            return channel.size();
        }
    }
}

{'fraction_non_alphanumeric': 0.08194289951798295, 'fraction_numerical': 0.00778642936596218, 'mean_word_length': 2.67574931880109, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1073002', 'n_tokens_mistral': 739, 'n_tokens_neox': 712, 'n_words': 210}