/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* See LICENSE.txt included in this distribution for the specific
* language governing permissions and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at LICENSE.txt.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Portions Copyright 2012 Jens Elkner.
*/
/**
* The header of a crossfile.
*
* @author Jens Elkner
* @version $Revision$
*/
public class XrefHeader {
/** the default format version of a crossfile */
/** the size of the header in bytes */
private int version;
private int lines;
private long chars;
private boolean compressed;
/**
* Create a new default header for a crossfile of the given genre. Data
* section is assumed to be uncompressed and line and char counts are set
* to -1.
* @param genre genre of the file.
* @see XrefHeader#XrefHeader(Genre, boolean)
*/
this(genre, false);
}
/**
* Create a new default header for a crossfile of the given genre and
* parameters. Line and char counts are set to -1.
* @param genre genre of the file.
* @param compressed {@code true} if data section is compressed
* @see XrefHeader#XrefHeader(Genre, boolean, int, long)
*/
}
/**
* Create a new default header for a crossfile of the given genre and
* parameters.
* @param genre genre of the data section.
* @param compressed {@code true} if data section is compressed
* @param lines number of lines represented by the data section. {@code -1}
* implies unknown.
* @param chars number of characters in the [compressed] data section.
*/
throw new IllegalArgumentException("genre null is not allowed");
}
this.compressed = compressed;
}
/**
* Creates a ByteBuffer backed by an new byte array of {@link #HEADER_SZ}
* and fills in all relevant metadata.
*
* @return an unshared byte buffer
*/
return bb;
}
/**
* Create a new instance by reading the required number of bytes
* from the given byte array starting at index 0.
* @param header byte array containing the header bytes.
* @throws IOException if the header is invalid.
*/
throw new IOException("invalid header");
}
}
+ " this may lead to unexpected results (supported is "
+ VERSION + ").");
}
throw new IOException("invalid header");
}
}
/**
* Create a new instance by reading the appropriate number of header bytes
* from the given stream.
* @param in from where to read the header.
* @throws IOException if the header is invalid or other error occures when
* reading the stream.
*/
this(readHeader(in));
}
int count = 0;
if (i < 0) {
throw new IOException("invalid header");
}
count += i;
}
return header;
}
/**
* Write the header to the given stream.
* @param out where to write the header.
* @throws IOException
*/
}
/**
* Get the number of characters, which follow the header. NOTE: NOT the
* compressed size!
* @return number of characters in the data section. {@code -1} implies
* unknown.
*/
public long getSize() {
return chars;
}
/**
* Set the number of characters, which follow the header. NOTE: NOT the
* compressed size!
* @param size number of characters in the data section. {@code -1} implies
* unknown.
*/
}
/**
* Get the number of lines represented by the data section.
* @return number of lines. {@code -1} implies unknown.
*/
public int getLines() {
return lines;
}
/**
* Set the number of lines represented by the data section.
* @param lines number of lines. {@code -1} implies unknown.
*/
}
/**
* Get the version of the header (file format).
* @return a number > 0.
*/
public int getVersion() {
return version;
}
/**
* The genre to which the data section belongs to.
* @return a non-{@code null} value.
*/
return genre;
}
/**
* Check, whether the data section of the file is compressed.
* @return {@code true} if compressed.
*/
public boolean isCompressed() {
return compressed;
}
/**
* {@inheritDoc}
*/
}
}