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

morfologik.fsa.FSAHeader Maven / Gradle / Ivy

Go to download

Morfologik provides high quality lemmatisation for the Polish language, along with tools for building and using byte-based finite state automata.

There is a newer version: 2.1.9
Show newest version
package morfologik.fsa;

import java.io.IOException;
import java.io.InputStream;

import morfologik.util.FileUtils;
import static morfologik.util.FileUtils.*;

/**
 * Standard FSA file header, as described in fsa package documentation. 
 */
final class FSAHeader {
	/**
	 * FSA magic (4 bytes).
	 */
	public final static int FSA_MAGIC = ('\\' << 24) | ('f' << 16) | ('s' << 8) | ('a');

	/**
	 * Maximum length of the header block.
	 */
	public static final int MAX_HEADER_LENGTH = 4 + 8;
	
	/** FSA version number. */
	public byte version;

	/** Filler character. */
	public byte filler;
	
	/** Annotation character. */
	public byte annotation;
	
	/** Goto field (may be a compound, depending on the automaton version). */
	public byte gtl;

	/**
	 * Read FSA header from a stream, consuming its bytes.
	 * 
	 * @throws IOException If the stream ends prematurely or if it contains invalid data.
	 */
	public static FSAHeader read(InputStream in) throws IOException {
		if (FSA_MAGIC != FileUtils.readInt(in))
			throw new IOException("Invalid file header magic bytes.");

		final FSAHeader h = new FSAHeader();
		h.version = readByte(in);
		h.filler = readByte(in);
		h.annotation = readByte(in);
		h.gtl = readByte(in);

	    return h;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy