?? dcwthematicindex.java
字號:
int[] values = null; try { int index = Arrays.binarySearch(indexData, valueIndex); if (index >= 0) { IndexRecord ir = indexData[index]; int offset = ir.offset; int numvals = ir.numvals; if ((typeOfIndex == 'T') || (typeOfIndex == 'I')) { if (numvals == 0) { values = new int[1]; values[0] = offset; } else { values = new int[numvals]; reopen(offset); for (int j = 0; j < numvals; j++) { values[j] = readIndexWithFieldType(dataTypeSpecifier); } } return values; } else if ((typeOfIndex == 'B') || (typeOfIndex == 'G')) { // Don't really do anything with this type of // index... int shortread = numberOfRows / 16; if ((numberOfRows % 16) != 0) { shortread++; } if (Debug.debugging("vpfserver")) { System.out.println("Reading a bunch of shorts: " + shortread); System.out.println("Starting at offset: " + inputFile.getFilePointer()); } BitSet bits = new BitSet(numberOfRows); int cnt = 0; for (int shortcnt = 0; shortcnt < shortread; shortcnt++) { short s = inputFile.readShort(); for (int k = 0; k < 16; k++) { cnt++; if ((s & 0x1) == 1) { bits.set(cnt); } s >>= 1; } } StringBuffer prt = new StringBuffer(); for (int j = 1; j <= bits.size(); j++) { if (bits.get(j)) { prt.append(", " + j); } } System.out.println(prt); } else { throw new FormatException("Unidentied TMI format"); } } } catch (EOFException e) { throw new FormatException("Hit Premature EOF in thematic index"); } catch (IOException i) { throw new FormatException("Encountered IO Exception: " + i.getMessage()); } return values; } /** * Utility method to read rows. * * @param ft the field type * @returns the value read from the file */ private int readIndexWithFieldType(char ft) throws EOFException, FormatException { switch (ft) { case 'S': return (int) inputFile.readShort(); case 'I': return inputFile.readInteger(); } throw new FormatException("Unrecognized FieldTypeOfIndex"); } private Object readIndexField(char dts, int textlen) throws EOFException, FormatException { switch (dts) { case 'I': return new Integer(inputFile.readInteger()); case 'T': return inputFile.readFixedLengthString(textlen); case 'S': return new Short(inputFile.readShort()); case 'F': return new Float(inputFile.readFloat()); case 'R': return new Double(inputFile.readDouble()); } throw new FormatException("Unrecognized field index type"); } private String trim(String s) { StringBuffer ns = new StringBuffer(); char foo[] = s.toCharArray(); for (int i = 0; i < foo.length; i++) { if ((foo[i] == ' ') || (foo[i] == 0)) { break; } ns.append(foo[i]); } return ns.toString(); } /** * Returns the number of distinct indexed values * * @return the number of distinct indexed values */ public int getNumberOfCodes() { return numberOfCodes; } /** * Returns the number of rows indexed * * @return the number of rows indexed */ public int getNumberOfRows() { return numberOfRows; } /** * Returns the type of index (refer to VPF spec for valid values) * * @return the type of index (refer to VPF spec for valid values) */ public char getTypeOfIndex() { return typeOfIndex; } /** * Returns the type of the field being indexed * * @return the type of the field being indexed */ public char getFieldTypeOfIndex() { return fieldTypeOfIndex; } /** * Returns the number of elements in the index field * * @return the number of elements in the index field */ public int getNumberOfDataElements() { return numberOfDataElement; } /** * Returns the datatype specifier * * @return the datatype specifier */ public char getDataTypeSpecifier() { return dataTypeSpecifier; } /** * Returns the name of the table being indexed * * @return the name of the table being indexed */ public String getTableIndexed() { return tableIndexed; } /** * Returns the name of the column being indexed * * @return the name of the column being indexed */ public String getColumnIndexed() { return columnIndexed; } public boolean getSorted() { return sorted; } /** Closes the associated input file. (may later get reopened) */ public synchronized void close() throws FormatException { try { if (inputFile != null) { inputFile.close(); } inputFile = null; } catch (IOException i) { throw new FormatException("DcwThematicIndex: Can't close file " + filename + ": " + i.getMessage()); } } /** * Reopen the associated input file. * * @param offset the byte offset to seek to upon reopening the * file. If offset is invalid (less than 1), then the input * stream is in an undefined location. * @exception FormatException some error was encountered in * reopening file or seeking to the desired row. * @see #close() */ public synchronized void reopen(int offset) throws FormatException { try { if (inputFile == null) { inputFile = new BinaryBufferedFile(filename); inputFile.byteOrder(byteOrder); } if (offset > 0) { inputFile.seek(offset); } } catch (IOException i) { throw new FormatException("DcwThematicIndex: Can't open file " + filename + ": " + i.getMessage()); } }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -