All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.vesalainen.parser.util.ScatteringByteChannelInput Maven / Gradle / Ivy

Go to download

Java Lookahead Parser Generator. Generator produces LALR(k) parsers. Grammar rules are entered using annotations. Rule annotation can be attached to reducer method, which keeps rule and it's action together.

The newest version!
/*
 * Copyright (C) 2014 Timo Vesalainen
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 */

package org.vesalainen.parser.util;

import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ScatteringByteChannel;
import java.nio.charset.Charset;
import java.util.EnumSet;
import java.util.zip.Checksum;
import org.vesalainen.parser.ParserFeature;
import static org.vesalainen.parser.ParserFeature.*;

/**
 *
 * @author Timo Vesalainen
 */
public class ScatteringByteChannelInput extends ByteInput
{

    public ScatteringByteChannelInput(ScatteringByteChannel in, int size, EnumSet features)
    {
        super(size, features.contains(UseDirectBuffer), features);
        includeLevel.in = in;
    }

    public ScatteringByteChannelInput(byte[] array, EnumSet features)
    {
        super(array, features);
    }

    public ScatteringByteChannelInput(ByteBuffer buffer, EnumSet features)
    {
        super(buffer, features);
    }

    @Override
    protected int fill(ScatteringByteChannel input, ByteBuffer[] array) throws IOException
    {
        return (int) input.read(array);
    }

    @Override
    protected void unread(ScatteringByteChannel input) throws IOException
    {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    protected void close(ScatteringByteChannel input) throws IOException
    {
        input.close();
    }

    @Override
    public void include(InputStream is, String source) throws IOException
    {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void include(InputStream is, String cs, String source) throws IOException
    {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void include(InputStream is, Charset cs, String source) throws IOException
    {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void include(Readable in, String source) throws IOException
    {
        throw new UnsupportedOperationException("Not supported.");
    }

    @Override
    public void setChecksum(Checksum checksum)
    {
        if (checksum != null)
        {
            if (array != null)
            {
                int start = cursor % size - length;
                int lsz = size - start;
                if (lsz < length)
                {
                    checksum.update(array, start, lsz);
                    checksum.update(array, 0, length - lsz);
                }
                else
                {
                    checksum.update(array, start, length);
                }
            }
            else
            {
                super.setChecksum(checksum);
            }
        }
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy