org.opentestsystem.delivery.testreg.upload.TextFileAppender.java Source code

Java tutorial

Introduction

Here is the source code for org.opentestsystem.delivery.testreg.upload.TextFileAppender.java

Source

/*******************************************************************************
 * Educational Online Test Delivery System
 * Copyright (c) 2013 American Institutes for Research
 * 
 * Distributed under the AIR Open Source License, Version 1.0
 * See accompanying file AIR-License-1_0.txt or at
 * http://www.smarterapp.org/documents/American_Institutes_for_Research_Open_Source_Software_License.pdf
 ******************************************************************************/

package org.opentestsystem.delivery.testreg.upload;

import java.io.InputStream;
import java.io.SequenceInputStream;

import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Value;

public class TextFileAppender implements FileAppender {

    @Value("#{systemProperties['line.separator']}")
    private String lineSeperator;

    private InputStream getInputStream(String text) {
        return IOUtils.toInputStream(text + lineSeperator);
    }

    @Override
    public InputStream insertAtTop(String text, InputStream inputStream) {
        return new SequenceInputStream(getInputStream(text), inputStream);
    }
}