Example usage for org.springframework.batch.item.file NonTransientFlatFileException NonTransientFlatFileException

List of usage examples for org.springframework.batch.item.file NonTransientFlatFileException NonTransientFlatFileException

Introduction

In this page you can find the example usage for org.springframework.batch.item.file NonTransientFlatFileException NonTransientFlatFileException.

Prototype

public NonTransientFlatFileException(String message, Throwable cause, String input, int lineNumber) 

Source Link

Usage

From source file:egovframework.rte.bat.core.item.file.EgovFlatFileByteReader.java

/**
 * OS? ?  ? ?  ?? ?? Method/*w  w  w .j  a va  2  s . c om*/
 * @return
 */
private byte[] readLine() {
    if (b == null) {
        b = new byte[length + LINE_CRLF];
    }

    int line = 0;
    try {
        line = this.reader.read(b, offset, length + LINE_CRLF);
        if (line < 0) {
            return null;
        }
        lineCount++;
    } catch (IOException e) {
        noInput = true;
        throw new NonTransientFlatFileException("Unable to read from resource: [" + resource + "]", e,
                line + "", lineCount);
    }
    return b;
}

From source file:org.jasig.ssp.util.importer.job.csv.FlatFileItemReaderNewLine.java

/**
 * @return next line (skip comments).getCurrentResource
 *//*w w  w.  j a  v a2  s  . c  o  m*/
private String readLine() {

    if (reader == null) {
        throw new ReaderNotOpenException("Reader must be open before it can be read.");
    }

    String line = null;

    try {
        line = this.reader.readLine();
        if (line == null) {
            return null;
        }
        lineCount++;
        while (isComment(line)) {
            line = reader.readLine();
            if (line == null) {
                return null;
            }
            lineCount++;
        }

        while (isIncomplete(line)) {
            line = line + "\n" + reader.readLine();
        }

        line = applyRecordSeparatorPolicy(line);
    } catch (IOException e) {
        // Prevent IOException from recurring indefinitely
        // if client keeps catching and re-calling
        noInput = true;
        throw new NonTransientFlatFileException("Unable to read from resource: [" + resource + "]", e, line,
                lineCount);
    }
    return line;
}

From source file:org.springframework.batch.item.file.FlatFileItemReader.java

/**
 * @return next line (skip comments).getCurrentResource
 *///from   w  w w. j a  v  a2s  .  c o m
private String readLine() {

    if (reader == null) {
        throw new ReaderNotOpenException("Reader must be open before it can be read.");
    }

    String line = null;

    try {
        line = this.reader.readLine();
        if (line == null) {
            return null;
        }
        lineCount++;
        while (isComment(line)) {
            line = reader.readLine();
            if (line == null) {
                return null;
            }
            lineCount++;
        }

        line = applyRecordSeparatorPolicy(line);
    } catch (IOException e) {
        // Prevent IOException from recurring indefinitely
        // if client keeps catching and re-calling
        noInput = true;
        throw new NonTransientFlatFileException("Unable to read from resource: [" + resource + "]", e, line,
                lineCount);
    }
    return line;
}

From source file:org.springframework.batch.item.file.RegexFileItemReader.java

/**
 * @return next line (skip comments).getCurrentResource
 *///from   ww w  .  ja v  a 2 s.c  om
private String readLine() {

    if (reader == null) {
        throw new ReaderNotOpenException("Reader must be open before it can be read.");
    }

    String line = null;

    try {

        while (1 == 1) {

            boolean readed = readBuffer();
            if (!readed) {
                return null;
            }

            String bufferString = String.valueOf(buffer);
            Matcher matcher = pattern.matcher(bufferString);
            boolean found = matcher.find(offsetLastEnd);
            if (found) {
                offsetLastStart = matcher.start();
                offsetLastEnd = matcher.end();
                line = bufferString.substring(offsetLastStart, offsetLastEnd);
                lineCount++;
                break;

            } else {

                readBufferNeeded = true;

                if (offsetLastEnd != 0) {
                    int restLen = currentBufferSize - offsetLastEnd;
                    // move to beggining of buffer chunk after last item found
                    copy(buffer, offsetLastEnd, currentBufferSize - offsetLastEnd, 0);
                    Arrays.fill(buffer, restLen, buffer.length, (char) 0);

                    // new buffer's length will contain this chunk
                    currentBufferSize = bufferSize + restLen;
                    offsetBuffer = restLen;
                    offsetLastEnd = 0;

                } else {
                    // if can't find any item in current buffer then read next block
                    // and add to first one (remove previous block if needed)
                    offsetBuffer = bufferSize;
                    if (currentBufferSize == bufferSize) {

                        // first block stays, read next one after first
                        // blocks: 1 -> 12
                        currentBufferSize = 2 * bufferSize;

                    } else {
                        // copy second block to beginning, make room to next one, forget first
                        // blocks: 12 -> 23
                        copy(buffer, bufferSize, bufferSize, 0);
                        offsetBuffer = bufferSize;
                        currentBufferSize = 2 * bufferSize;
                    }
                }
            }
        }

        if (line == null) {
            return null;
        }

    } catch (IOException e) {
        // Prevent IOException from recurring indefinitely
        // if client keeps catching and re-calling
        noInput = true;
        throw new NonTransientFlatFileException("Unable to read from resource: [" + resource + "]", e, line,
                lineCount);
    }
    return line;
}