📄 basedisktable.java
字号:
return true; } } return true; } protected void parseMetaFile(File file) throws AxionException { ObjectInputStream in = null; try { in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file))); // read version number int ver = in.readInt(); if(ver != 0) { throw new AxionException("Can't parse meta file " + file + " for table " + getName() + ", unrecognized meta file version " + ver); } else { // read number of columns int I = in.readInt(); for(int i=0;i<I;i++) { // read column name String name = in.readUTF(); // read data type class name String dtypename = in.readUTF(); // create instance of datatype DataType type = null; try { Class clazz = Class.forName(dtypename); type = (DataType)(clazz.newInstance()); } catch(ClassNotFoundException e) { throw new AxionException("Can't load table " + getName() + ", data type " + dtypename + " not found.",e); } catch(ClassCastException e) { throw new AxionException("Can't load table " + getName() + ", data type " + dtypename + " not a DataType.",e); } catch(InstantiationException e) { throw new AxionException("Can't load table " + getName() + ", data type " + dtypename + " can't be instantiated.",e); } catch(IllegalAccessException e) { throw new AxionException("Can't load table " + getName() + ", data type " + dtypename + " can't be instantiated.",e); } addColumn(new Column(name,type),false); } } } catch(IOException e) { throw new AxionException("Unable to parse meta file " + file + " for table " + getName(),e); } finally { try { in.close(); } catch(Exception e) { } } } protected void writeMetaFile(File file) throws AxionException { ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); // write version number out.writeInt(0); // write number of columns out.writeInt(getColumnCount()); // for each column for(int i=0,I=getColumnCount();i<I;i++) { Column col = getColumn(i); // write column name out.writeUTF(col.getName()); // write data type class name out.writeUTF(col.getDataType().getClass().getName()); } out.flush(); } catch(IOException e) { throw new AxionException("Unable to write meta file " + file + " for table " + getName(),e); } finally { try { out.close(); } catch(Exception e) { } } } /** * Writes a list of <tt>int</tt> values to a file. * * @param file the {@link File} to write to */ protected void writeIntFile(String file, IntList list) throws AxionException { DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); for(int i=0;i<list.size();i++) { out.writeInt(list.get(i)); } out.flush(); } catch(IOException e) { throw new AxionException("Unable to write to " + file,e); } finally { try { out.close(); } catch(Exception t) { } } } /** * Writes a list of <tt>long</tt> values to a file. * * @param file the {@link File} to write to */ protected void writeLongFile(String file, LongList list) throws AxionException { DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); for(int i=0;i<list.size();i++) { out.writeLong(list.get(i)); } out.flush(); } catch(IOException e) { throw new AxionException("Unable to write to " + file,e); } finally { try { out.close(); } catch(Exception t) { } } } /** * Appends a long value to a file. * * @param file the {@link File} to append to * @param value the value to write */ protected void appendLongFile(String file, long value) throws AxionException { DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file, true))); out.writeLong(value); } catch(IOException e) { throw new AxionException("Unable to write to " + file,e); } finally { try { out.close(); } catch(Exception t) { } } } /** * Appends several long values to a file. * * @param file the {@link File} to append to * @param values the values to write */ protected void appendLongFile(String file, LongList value) throws AxionException { DataOutputStream out = null; try { out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file, true))); for(LongIterator iter = value.iterator();iter.hasNext();) { out.writeLong(iter.next()); } } catch(IOException e) { throw new AxionException("Unable to write to " + file,e); } finally { try { out.close(); } catch(Exception t) { } } } /** * Reads a list of long values from a file. * * @param file the {@link File} to read from */ protected LongList parseLongFile(File file) throws AxionException { int count = (int)(file.length()/8L); LongList list = new ArrayUnsignedIntList(count); DataInputStream in = null; try { in = new DataInputStream(new BufferedInputStream(new FileInputStream(file),8192)); for(int i=0;i<count;i++) { list.add(in.readLong()); } return list; } catch(IOException e) { throw new AxionException("Unable to parse " + file,e); } finally { try { in.close(); } catch(Exception t) { } } } /** * Reads a list of int values from a file. * * @param file the {@link File} to read from */ protected IntList parseIntFile(File file) throws AxionException { int count = (int)(file.length()/4L); IntList list = new ArrayIntList(count); DataInputStream in = null; try { in = new DataInputStream(new BufferedInputStream(new FileInputStream(file))); for(int i=0;i<count;i++) { list.add(in.readInt()); } return list; } catch(IOException e) { throw new AxionException("Unable to parse " + file,e); } finally { try { in.close(); } catch(Exception t) { } } } //----------------------------------------------------------------- Private private File getMetaFile() { if(null == _metaFile) { _metaFile = new File(getRootDir(),getName() + ".meta"); } return _metaFile; } private void clearMetaFileReference() { _metaFile = null; } //--------------------------------------------------------------- Attributes private File _metaFile = null; private static Log _log = LogFactory.getLog(BaseDiskTable.class);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -