?? dcwthematicindex.java
字號:
// **********************************************************************// // <copyright>// // BBN Technologies// 10 Moulton Street// Cambridge, MA 02138// (617) 873-8000// // Copyright (C) BBNT Solutions LLC. All rights reserved.// // </copyright>// **********************************************************************// // $Source: /cvs/distapps/openmap/src/openmap/com/bbn/openmap/layer/vpf/DcwThematicIndex.java,v $// $RCSfile: DcwThematicIndex.java,v $// $Revision: 1.3.2.2 $// $Date: 2005/08/09 21:17:52 $// $Author: dietrick $// // **********************************************************************package com.bbn.openmap.layer.vpf;import java.io.IOException;import java.io.EOFException;import java.util.*;import com.bbn.openmap.io.*;import com.bbn.openmap.util.Debug;/** Read a VPF thematic index file. (VPF *.?ti files) */public class DcwThematicIndex { /** the file we read from */ private BinaryFile inputFile = null; /** read from file - length of header */ final private int headerSize; /** read from file - number of indexes (codes) */ final private int numberOfCodes; /** read from file - total number of rows indexed */ final private int numberOfRows; /** read from file - type of index */ final private char typeOfIndex; // T hematic /** read from file - field type of index */ final private char fieldTypeOfIndex; /** read from file - number of elements composing the index value */ final private int numberOfDataElement; /** read from file - the type of the index */ final private char dataTypeSpecifier; /** read from file - the table indexed */ final private String tableIndexed; /** read from file - the column indexed */ final private String columnIndexed; /** read from file (vpf 2407 only) - are the codes sorted */ final private boolean sorted; /** the list of index records */ private IndexRecord[] indexData; /** the name of the file being read */ // final protected File filename; final protected String filename; /** the byte order of the file */ protected boolean byteOrder; /** * A utility class used to record index records. */ public static class IndexRecord implements Comparable { /** the index (code) */ final Object index; /** the offset of the data */ final int offset; /** the number of values - 0 means the offset is the only value */ final int numvals; /** * Construct an index record * * @param index the index object * @param offset the offset of the data * @param numvals the number of values */ public IndexRecord(Object index, int offset, int numvals) { this.index = index; this.offset = offset; this.numvals = numvals; } public int compareTo(Object obj) { Object realobj = (obj instanceof IndexRecord) ? ((IndexRecord) obj).index : obj; return ((Comparable) index).compareTo(realobj); } } /** * Construct an index, assumes this is pre-VPF2407 format. * * @param filename the file to oped * @param border the byteorder */ public DcwThematicIndex(String filename, boolean border) throws FormatException { this(filename, border, false); } /** * Construct an index, assumes this is pre-VPF2407 format. * * @param filename the file to oped * @param border the byteorder * @param vpf2407 true for MILSTD-2407 format thematic index. * false will properly read a VPF2407 format index, but * will ignore one header field (sorted). true will * improperly read old-style data. */ public DcwThematicIndex(String filename, boolean border, boolean vpf2407) throws FormatException { this.filename = filename; byteOrder = border; reopen(0); if (Debug.debugging("vpfserver")) { System.out.println("DTI: opened the file " + filename); } try { headerSize = inputFile.readInteger(); numberOfCodes = inputFile.readInteger(); numberOfRows = inputFile.readInteger(); typeOfIndex = inputFile.readChar(); fieldTypeOfIndex = inputFile.readChar(); numberOfDataElement = inputFile.readInteger(); dataTypeSpecifier = inputFile.readChar(); tableIndexed = trim(inputFile.readFixedLengthString(12)).toLowerCase(); columnIndexed = trim(inputFile.readFixedLengthString(25)).toLowerCase(); sorted = (inputFile.readChar() == 'S') && vpf2407; inputFile.seek(60); //skips 3 unused bytes indexData = new IndexRecord[numberOfCodes]; if (Debug.debugging("vpfserver")) { System.out.println("HeaderSize = " + headerSize); System.out.println("Number of Codes = " + numberOfCodes); System.out.println("Number of Rows = " + numberOfRows); System.out.println("Type of Index = " + typeOfIndex); // if (typeOfIndex != 'T') // System.out.println(" *** Strange - dcw spec says it // will be T ***"); System.out.println("Field Type of Index = " + fieldTypeOfIndex); System.out.println("Number of Data Element = " + numberOfDataElement); System.out.println("Data Type Specifier = " + dataTypeSpecifier); System.out.println("Table Indexed = " + tableIndexed); System.out.println("Column Indexed = " + columnIndexed); System.out.println("Sorted = " + sorted); } StringBuffer pr = new StringBuffer(); for (int i = 0; i < numberOfCodes; i++) { indexData[i] = new IndexRecord(readIndexField(fieldTypeOfIndex, numberOfDataElement), inputFile.readInteger(), inputFile.readInteger()); if (Debug.debugging("vpfserver")) { pr = new StringBuffer("i = " + i); pr.append("; val = " + indexData[i].index.toString()); pr.append("; offset = " + indexData[i].offset); pr.append("; number of elts = " + indexData[i].numvals); if (i < 40) { System.out.println(pr.toString()); } } } if (!sorted) { Arrays.sort(indexData); } if (Debug.debugging("vpfserver") && (numberOfCodes > 40)) { System.out.println(pr.toString()); } Debug.message("vpfserver", "*** Finished Header Read ***"); if (Debug.debugging("vpfserver")) { if ((typeOfIndex == 'T') || (typeOfIndex == 'I')) { Debug.output("Normal Inverted Index Format"); } else if ((typeOfIndex == 'B') || (typeOfIndex == 'G')) { Debug.output("Scary Bitmap Index Format"); } else { throw new FormatException("Unidentied TMI format"); } Object[] indexes = getValueIndexes(); // We just know that these values are tile IDs. for (int j = 0; j < indexes.length; j++) { // int[] row = get(indexes[j]); // If you want to do some scary printout, code it // up here. } } close(); } catch (EOFException e) { throw new FormatException("Hit Premature EOF in thematic index"); } catch (IOException i) { throw new FormatException("Encountered IO Exception: " + i.getMessage()); } } /** * Returns the set of values indexed by this thematic index. * * @return the set of values indexed */ public Object[] getValueIndexes() { Object[] values = null; if (indexData != null) { values = new Object[indexData.length]; for (int i = 0; i < indexData.length; i++) { values[i] = indexData[i].index; } } return values; } /** * Returns the list of rows listed for this index * * @return an array of rows * @param valueIndex the value to look up */ public synchronized int[] get(Object valueIndex) throws FormatException {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -