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

com.thelastcheck.io.x9.X9OutputStreamRecordWriter Maven / Gradle / Ivy

There is a newer version: 2.5.3
Show newest version
/*******************************************************************************
 * Copyright (c) 2009-2015 The Last Check, LLC, All Rights Reserved
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * You may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.thelastcheck.io.x9;

import java.io.IOException;
import java.io.OutputStream;

import com.thelastcheck.commons.buffer.ByteArray;
import com.thelastcheck.io.base.OutputStreamRecordWriter;
import com.thelastcheck.io.base.Record;

public class X9OutputStreamRecordWriter extends OutputStreamRecordWriter {

	private ByteArray lengthPrefixBuffer = new ByteArray(4);

	public X9OutputStreamRecordWriter(OutputStream os) {
		super(os);
	}

	protected void writeRecord(Record record) throws IOException {
		X9Record x9Record = (X9Record) record;
		if (x9Record.recordStandardLevel() >= X9Record.STANDARD_LEVEL_DSTU) {
			int recordLength = x9Record.length();
			lengthPrefixBuffer.write(recordLength, 0);
			write(lengthPrefixBuffer);
		}
		write(x9Record.record());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy