ome.metakit.ColumnMap Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of metakit Show documentation
Show all versions of metakit Show documentation
A library for reading Metakit database files.
/*
* #%L
* OME Metakit package for reading Metakit database files.
* %%
* Copyright (C) 2011 - 2016 Open Microscopy Environment:
* - Board of Regents of the University of Wisconsin-Madison
* - Glencoe Software, Inc.
* - University of Dundee
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* .
* #L%
*/
package ome.metakit;
import java.io.IOException;
import java.util.ArrayList;
import loci.common.Constants;
import loci.common.RandomAccessInputStream;
/**
* Class representating a column mapping in a Metakit database file.
*
* @author Melissa Linkert melissa at glencoesoftware.com
*/
public class ColumnMap {
// -- Fields --
private ArrayList values = new ArrayList();
private Column col;
private RandomAccessInputStream stream;
private int rowCount;
// -- Constructors --
public ColumnMap(Column col, RandomAccessInputStream stream, int rowCount) {
this.col = col;
this.stream = stream;
this.rowCount = rowCount;
try {
setup();
}
catch (IOException e) {
}
}
// -- ColumnMap API methods --
/** Return the list of values in this map's column. */
public ArrayList getValueList() {
return values;
}
/** Return an array of the values in this map's column. */
public Object[] getValues() {
return values.toArray(new Object[values.size()]);
}
/**
* Return whether or not this map represents a fixed-type column.
* Fixed-type columns have type "I", "F", "D", or "L".
*/
public boolean isFixedMap() {
char type = col.getTypeString().charAt(0);
return type != 'S' && type != 'B';
}
// -- Helper methods --
/**
* Read the data values for the current column.
*/
private void setup() throws IOException {
if (isFixedMap()) {
// read a single IVecRef
int ivecSize = MetakitTools.readBpInt(stream);
if (ivecSize > 0) {
int ivecPointer = MetakitTools.readBpInt(stream);
long fp = stream.getFilePointer();
stream.seek(ivecPointer);
for (int i=0; i 0) {
catalogIvecPointer = MetakitTools.readBpInt(stream);
}
long fp = stream.getFilePointer();
stream.seek(mapIvecPointer);
int[] byteCounts = new int[rowCount];
int bits = (mapIvecSize * 8) / rowCount;
for (int i=0; i= 32) {
return stream.readInt();
}
long fp = stream.getFilePointer();
stream.skipBytes((index * bits) / 8);
int b = stream.read();
int mask = (int) Math.pow(2, bits) - 1;
int bitIndex = index % (8 / bits);
int value = b & (mask << (bitIndex * bits));
value >>= ((8 - (bitIndex * bits)) % 8);
stream.seek(fp);
return value;
}
}