
org.cyclopsgroup.caff.format.FixLengthFormat Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of caff Show documentation
Show all versions of caff Show documentation
Java conversion and formatting framework
The newest version!
package org.cyclopsgroup.caff.format;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import org.cyclopsgroup.caff.CharArrayCharSequence;
/**
* Format implementation that parse and format fix length fields
*
* @author Jiaqi Guo
* @param Type of bean to format/parse
*/
public class FixLengthFormat extends Format {
private final FixLengthImpl impl;
/**
* @param beanType Type of bean
*/
public FixLengthFormat(Class beanType) {
super(beanType);
impl = new FixLengthImpl(beanType);
}
@Override
public char[] formatToCharArray(T object) {
return impl.print(object);
}
@Override
public T parse(CharSequence content) {
T bean = createBean();
populate(bean, content);
return bean;
}
@Override
public T parse(Reader reader) throws IOException {
char[] line = new char[impl.type.length()];
reader.read(line);
return parse(new CharArrayCharSequence(line));
}
private void populate(T object, CharSequence line) {
impl.populate(object, line);
}
@Override
public void populate(T object, Reader reader) throws IOException {
char[] line = new char[impl.type.length()];
reader.read(line);
populate(object, new CharArrayCharSequence(line));
}
@Override
public void print(T object, Writer out) throws IOException {
char[] output = impl.print(object);
out.write(output);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy