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

org.eclipse.jetty.util.ReadLineInputStream Maven / Gradle / Ivy

Go to download

Ehcache is an open source, standards-based cache used to boost performance, offload the database and simplify scalability. Ehcache is robust, proven and full-featured and this has made it the most widely-used Java-based cache.

There is a newer version: 2.10.9.2
Show newest version
//
//  ========================================================================
//  Copyright (c) 1995-2018 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//

package org.eclipse.jetty.util;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.EnumSet;

import org.eclipse.jetty.util.MultiPartInputStreamParser.NonCompliance;

/**
 * ReadLineInputStream
 *
 * Read from an input stream, accepting CR/LF, LF or just CR.
 */
@Deprecated
public class ReadLineInputStream extends BufferedInputStream
{
    boolean _seenCRLF;
    boolean _skipLF;
    private EnumSet _lineTerminations = EnumSet.noneOf(Termination.class);
    public EnumSet getLineTerminations() { return _lineTerminations; }
    public enum Termination
    {
        CRLF,
        LF,
        CR,
        EOF
    }
    
    public ReadLineInputStream(InputStream in)
    {
        super(in);
    }

    public ReadLineInputStream(InputStream in, int size)
    {
        super(in,size);
    }
    
    public String readLine() throws IOException
    {
        mark(buf.length);
                
        while (true)
        {
            int b=super.read();
            
            if (markpos < 0)
                throw new IOException("Buffer size exceeded: no line terminator");
            
            if(_skipLF && b!='\n')
                _lineTerminations.add(Termination.CR);

            if (b==-1)
            {
                int m=markpos;
                markpos=-1;
                if (pos>m)
                {
                    _lineTerminations.add(Termination.EOF);
                    return new String(buf,m,pos-m, StandardCharsets.UTF_8);
                }
                return null;
            }
            
            if (b=='\r')
            {
                int p=pos;
                
                // if we have seen CRLF before, hungrily consume LF
                if (_seenCRLF && pos0)
        {
            _skipLF=false;
            if (_seenCRLF)
            {
                int b = super.read();
                if (b==-1)
                    return -1;
                
                if (b!='\n')
                {
                    buf[off]=(byte)(0xff&b);
                    return 1+super.read(buf,off+1,len-1);
                }
            }
        }
        
        return super.read(buf,off,len);
    }
    
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy