List of usage examples for java.io DataInputStream readDouble
public final double readDouble() throws IOException
readDouble
method of DataInput
. From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>PropertyState</code> from the data input stream. * * @param in the input stream/*from w w w . ja v a 2s. co m*/ * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkPropertyState(DataInputStream in) { int type; try { type = in.readInt(); short modCount = (short) ((type >> 16) | 0xffff); type &= 0xffff; log.debug(" PropertyType: " + PropertyType.nameFromValue(type)); log.debug(" ModCount: " + modCount); } catch (IOException e) { log.error("Error while reading property type: " + e); return false; } try { boolean isMV = in.readBoolean(); log.debug(" MultiValued: " + isMV); } catch (IOException e) { log.error("Error while reading multivalued: " + e); return false; } try { String defintionId = in.readUTF(); log.debug(" DefinitionId: " + defintionId); } catch (IOException e) { log.error("Error while reading definition id: " + e); return false; } int count; try { count = in.readInt(); log.debug(" num values: " + count); } catch (IOException e) { log.error("Error while reading number of values: " + e); return false; } for (int i = 0; i < count; i++) { switch (type) { case PropertyType.BINARY: int size; try { size = in.readInt(); log.debug(" binary size: " + size); } catch (IOException e) { log.error("Error while reading size of binary: " + e); return false; } if (size == BINARY_IN_DATA_STORE) { try { String s = in.readUTF(); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" global data store id: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else if (size == BINARY_IN_BLOB_STORE) { try { String s = in.readUTF(); log.debug(" blobid: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else { // short values into memory byte[] data = new byte[size]; try { in.readFully(data); log.debug(" binary: " + data.length + " bytes"); } catch (IOException e) { log.error("Error while reading inlined binary: " + e); return false; } } break; case PropertyType.DOUBLE: try { double d = in.readDouble(); log.debug(" double: " + d); } catch (IOException e) { log.error("Error while reading double value: " + e); return false; } break; case PropertyType.DECIMAL: try { BigDecimal d = readDecimal(in); log.debug(" decimal: " + d); } catch (IOException e) { log.error("Error while reading decimal value: " + e); return false; } break; case PropertyType.LONG: try { double l = in.readLong(); log.debug(" long: " + l); } catch (IOException e) { log.error("Error while reading long value: " + e); return false; } break; case PropertyType.BOOLEAN: try { boolean b = in.readBoolean(); log.debug(" boolean: " + b); } catch (IOException e) { log.error("Error while reading boolean value: " + e); return false; } break; case PropertyType.NAME: try { Name name = readQName(in); log.debug(" name: " + name); } catch (IOException e) { log.error("Error while reading name value: " + e); return false; } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: try { NodeId id = readID(in); log.debug(" reference: " + id); } catch (IOException e) { log.error("Error while reading reference value: " + e); return false; } break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len; try { len = in.readInt(); log.debug(" size of string value: " + len); } catch (IOException e) { log.error("Error while reading size of string value: " + e); return false; } try { byte[] bytes = new byte[len]; in.readFully(bytes); String s = new String(bytes, "UTF-8"); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" string: " + s); } catch (IOException e) { log.error("Error while reading string value: " + e); return false; } } } return true; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>PropertyState</code> from the data input stream. * * @param in the input stream/*from w w w . jav a2 s . c o m*/ * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkPropertyState(DataInputStream in) { int type; try { type = in.readInt(); short modCount = (short) ((type >> 16) | 0xffff); type &= 0xffff; log.debug(" PropertyType: " + PropertyType.nameFromValue(type)); log.debug(" ModCount: " + modCount); } catch (IOException e) { log.error("Error while reading property type: " + e); return false; } try { boolean isMV = in.readBoolean(); log.debug(" MultiValued: " + isMV); } catch (IOException e) { log.error("Error while reading multivalued: " + e); return false; } try { String defintionId = in.readUTF(); log.debug(" DefinitionId: " + defintionId); } catch (IOException e) { log.error("Error while reading definition id: " + e); return false; } int count; try { count = in.readInt(); log.debug(" num values: " + count); } catch (IOException e) { log.error("Error while reading number of values: " + e); return false; } for (int i = 0; i < count; i++) { switch (type) { case PropertyType.BINARY: int size; try { size = in.readInt(); log.debug(" binary size: " + size); } catch (IOException e) { log.error("Error while reading size of binary: " + e); return false; } if (size == BINARY_IN_DATA_STORE) { try { String s = in.readUTF(); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" global data store id: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else if (size == BINARY_IN_BLOB_STORE) { try { String s = in.readUTF(); log.debug(" blobid: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else { // short values into memory byte[] data = new byte[size]; try { in.readFully(data); log.debug(" binary: " + data.length + " bytes"); } catch (IOException e) { log.error("Error while reading inlined binary: " + e); return false; } } break; case PropertyType.DOUBLE: try { double d = in.readDouble(); log.debug(" double: " + d); } catch (IOException e) { log.error("Error while reading double value: " + e); return false; } break; case PropertyType.DECIMAL: try { BigDecimal d = readDecimal(in); log.debug(" decimal: " + d); } catch (IOException e) { log.error("Error while reading decimal value: " + e); return false; } break; case PropertyType.LONG: try { double l = in.readLong(); log.debug(" long: " + l); } catch (IOException e) { log.error("Error while reading long value: " + e); return false; } break; case PropertyType.BOOLEAN: try { boolean b = in.readBoolean(); log.debug(" boolean: " + b); } catch (IOException e) { log.error("Error while reading boolean value: " + e); return false; } break; case PropertyType.NAME: try { Name name = readQName(in); log.debug(" name: " + name); } catch (IOException e) { log.error("Error while reading name value: " + e); return false; } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: try { UUID uuid = readUUID(in); log.debug(" reference: " + uuid); } catch (IOException e) { log.error("Error while reading reference value: " + e); return false; } break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len; try { len = in.readInt(); log.debug(" size of string value: " + len); } catch (IOException e) { log.error("Error while reading size of string value: " + e); return false; } try { byte[] bytes = new byte[len]; in.readFully(bytes); String s = new String(bytes, "UTF-8"); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" string: " + s); } catch (IOException e) { log.error("Error while reading string value: " + e); return false; } } } return true; }
From source file:org.ramadda.repository.database.DatabaseManager.java
/** * _more_// ww w . ja va 2s. c o m * * @param file _more_ * @param doDrop _more_ * * @throws Exception _more_ */ public void loadRdbFile(String file, boolean doDrop) throws Exception { DataInputStream dis = new DataInputStream(new FileInputStream(file)); XmlEncoder encoder = new XmlEncoder(); String tableXml = readString(dis); List<TableInfo> tableInfos = (List<TableInfo>) encoder.toObject(tableXml); System.err.println("# table infos:" + tableInfos.size()); Hashtable<String, TableInfo> tables = new Hashtable<String, TableInfo>(); StringBuffer sql = new StringBuffer(); StringBuffer drop = new StringBuffer(); for (TableInfo tableInfo : tableInfos) { tables.put(tableInfo.getName(), tableInfo); drop.append("drop table " + tableInfo.getName() + ";\n"); sql.append("CREATE TABLE " + tableInfo.getName() + " (\n"); for (int i = 0; i < tableInfo.getColumns().size(); i++) { ColumnInfo column = tableInfo.getColumns().get(i); if (i > 0) { sql.append(",\n"); } sql.append(column.getName()); sql.append(" "); int type = column.getType(); if (type == ColumnInfo.TYPE_TIMESTAMP) { sql.append("ramadda.datetime"); } else if (type == ColumnInfo.TYPE_VARCHAR) { sql.append("varchar(" + column.getSize() + ")"); } else if (type == ColumnInfo.TYPE_INTEGER) { sql.append("int"); } else if (type == ColumnInfo.TYPE_DOUBLE) { sql.append("ramadda.double"); } else if (type == ColumnInfo.TYPE_BIGINT) { sql.append("ramadda.bigint"); } else if (type == ColumnInfo.TYPE_SMALLINT) { sql.append("int"); } else if (type == ColumnInfo.TYPE_CLOB) { sql.append(convertType("clob", column.getSize())); } else if (type == ColumnInfo.TYPE_BLOB) { sql.append(convertType("blob", column.getSize())); } else if (type == ColumnInfo.TYPE_UNKNOWN) { // sql.append(convertType("blob", column.getSize())); } else { throw new IllegalStateException("Unknown column type:" + type); } } sql.append(");\n"); for (IndexInfo indexInfo : tableInfo.getIndices()) { sql.append("CREATE INDEX " + indexInfo.getName() + " ON " + tableInfo.getName() + " (" + indexInfo.getColumnName() + ");\n"); } } // System.err.println(drop); // System.err.println(sql); //TODO: if (doDrop) { loadSql(drop.toString(), true, false); } loadSql(convertSql(sql.toString()), false, true); TableInfo tableInfo = null; int rows = 0; Connection connection = getConnection(); try { while (true) { int what = dis.readInt(); if (what == DUMPTAG_TABLE) { String tableName = readString(dis); tableInfo = tables.get(tableName); if (tableInfo == null) { throw new IllegalArgumentException("No table:" + tableName); } if (tableInfo.statement == null) { String insert = SqlUtil.makeInsert(tableInfo.getName(), tableInfo.getColumnNames()); tableInfo.statement = connection.prepareStatement(insert); } System.err.println("importing table:" + tableInfo.getName()); continue; } if (what == DUMPTAG_END) { break; } if (what != DUMPTAG_ROW) { throw new IllegalArgumentException("Unkown tag:" + what); } rows++; if ((rows % 1000) == 0) { System.err.println("rows:" + rows); } Object[] values = new Object[tableInfo.getColumns().size()]; int colCnt = 0; for (ColumnInfo columnInfo : tableInfo.getColumns()) { int type = columnInfo.getType(); if (type == ColumnInfo.TYPE_TIMESTAMP) { long dttm = dis.readLong(); values[colCnt++] = new Date(dttm); } else if (type == ColumnInfo.TYPE_VARCHAR) { String s = readString(dis); if ((s != null) && (s.length() > 5000)) { //A hack for old dbs if (tableInfo.getName().equals("metadata")) { s = s.substring(0, 4999); System.err.println("clipping: " + tableInfo.getName() + "." + columnInfo.getName()); } } values[colCnt++] = s; } else if (type == ColumnInfo.TYPE_INTEGER) { values[colCnt++] = new Integer(dis.readInt()); } else if (type == ColumnInfo.TYPE_DOUBLE) { values[colCnt++] = new Double(dis.readDouble()); } else if (type == ColumnInfo.TYPE_CLOB) { values[colCnt++] = readString(dis); } else if (type == ColumnInfo.TYPE_BLOB) { values[colCnt++] = readString(dis); } else if (type == ColumnInfo.TYPE_BIGINT) { long v = dis.readLong(); values[colCnt++] = new Long(v); } else if (type == ColumnInfo.TYPE_SMALLINT) { short v = dis.readShort(); values[colCnt++] = new Short(v); } else if (type == ColumnInfo.TYPE_UNKNOWN) { } else { throw new IllegalArgumentException( "Unknown type for table" + tableInfo.getName() + " " + type); } } setValues(tableInfo.statement, values); tableInfo.statement.addBatch(); tableInfo.batchCnt++; if (tableInfo.batchCnt > 1000) { tableInfo.batchCnt = 0; tableInfo.statement.executeBatch(); } } //Now finish up the batch for (TableInfo ti : tableInfos) { if (ti.batchCnt > 0) { ti.batchCnt = 0; ti.statement.executeBatch(); } } } finally { IOUtil.close(dis); closeConnection(connection); } System.err.println("imported " + rows + " rows"); }