List of usage examples for java.io DataInputStream readBoolean
public final boolean readBoolean() throws IOException
readBoolean
method of DataInput
. From source file:org.structr.core.graph.SyncCommand.java
private static Object readObject(final DataInputStream inputStream, final byte type) throws IOException { switch (type) { case 0:/*ww w. j a v a2 s . c o m*/ case 1: return inputStream.readByte(); case 2: case 3: return inputStream.readShort(); case 4: case 5: return inputStream.readInt(); case 6: case 7: return inputStream.readLong(); case 8: case 9: return inputStream.readFloat(); case 10: case 11: return inputStream.readDouble(); case 12: case 13: return inputStream.readChar(); case 14: case 15: return new String(deserializeData(inputStream), "UTF-8"); // this doesn't work with very long strings //return inputStream.readUTF(); case 16: case 17: return inputStream.readBoolean(); } return null; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream//w w w . j av a2 s .c om * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId in.readUTF(); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.REFERENCE: val = InternalValue.create(readUUID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream// w w w . j a va2s . c o m * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId entry.setPropDefId(PropDefId.valueOf(in.readUTF())); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.DECIMAL: val = InternalValue.create(readDecimal(in)); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: val = InternalValue.create(readID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream//from w w w .j av a 2 s . c o m * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId entry.setPropDefId(PropDefId.valueOf(in.readUTF())); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.DECIMAL: val = InternalValue.create(readDecimal(in)); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: val = InternalValue.create(readUUID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:org.getspout.spout.packet.PacketAddonData.java
@SuppressWarnings("unchecked") public void readData(DataInputStream input) throws IOException { String id = PacketUtil.readString(input); boolean sandboxed = SpoutClient.isSandboxed(); SpoutClient.enableSandbox();/*w w w . ja v a 2 s. com*/ try { Class<? extends AddonPacket> packetClass = AddonPacket.getPacketFromId(id); Constructor<? extends AddonPacket> constructor = null; Constructor<? extends AddonPacket>[] constructors = (Constructor<? extends AddonPacket>[]) packetClass .getConstructors(); for (Constructor<? extends AddonPacket> c : constructors) { if (c.getGenericParameterTypes().length == 0) { constructor = c; break; } } packet = constructor.newInstance(); } catch (Exception e) { e.printStackTrace(); } if (!sandboxed) { SpoutClient.disableSandbox(); } int size = input.readInt(); compressed = input.readBoolean(); data = new byte[size]; input.readFully(data); }
From source file:org.hyperic.hq.agent.db.DiskList.java
/** * A quick routine, which simply zips through the index file, * pulling out information about which records are free. * * We open up the file seperately here, so we can use the * buffered input stream, which makes our initial startup much * faster, if there is a lot of data sitting in the list. *//*ww w. j a v a 2 s . com*/ private void genFreeList(File idxFile) throws IOException { BufferedInputStream bIs; FileInputStream fIs = null; DataInputStream dIs; this.firstRec = -1; this.lastRec = -1; // TreeSet is used here to ensure a natural ordering of // the elements. this.freeList = new TreeSet(); try { fIs = new FileInputStream(idxFile); bIs = new BufferedInputStream(fIs); dIs = new DataInputStream(bIs); for (long idx = 0;; idx++) { boolean used; long prev, next; try { used = dIs.readBoolean(); } catch (EOFException exc) { break; } prev = dIs.readLong(); next = dIs.readLong(); if (used == false) { this.freeList.add(new Long(idx)); } else { if (prev == -1) { this.firstRec = idx; } if (next == -1) { this.lastRec = idx; } } } } catch (FileNotFoundException exc) { return; } finally { try { if (fIs != null) { fIs.close(); } } catch (IOException exc) { } } }
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/* www .ja va 2 s .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.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.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.apache.hadoop.hdfs.server.datanode.DataXceiver.java
/** * Write a block to disk.// w ww .jav a 2 s . c o m * * @param in The stream to read from * @throws IOException */ private void writeBlock(DataInputStream in) throws IOException { DatanodeInfo srcDataNode = null; LOG.debug("writeBlock receive buf size " + s.getReceiveBufferSize() + " tcp no delay " + s.getTcpNoDelay()); // // Read in the header // Block block = new Block(in.readLong(), dataXceiverServer.estimateBlockSize, in.readLong()); LOG.info("Receiving block " + block + " src: " + remoteAddress + " dest: " + localAddress); int pipelineSize = in.readInt(); // num of datanodes in entire pipeline boolean isRecovery = in.readBoolean(); // is this part of recovery? String client = Text.readString(in); // working on behalf of this client boolean hasSrcDataNode = in.readBoolean(); // is src node info present if (hasSrcDataNode) { srcDataNode = new DatanodeInfo(); srcDataNode.readFields(in); } int numTargets = in.readInt(); if (numTargets < 0) { throw new IOException("Mislabelled incoming datastream."); } DatanodeInfo targets[] = new DatanodeInfo[numTargets]; for (int i = 0; i < targets.length; i++) { DatanodeInfo tmp = new DatanodeInfo(); tmp.readFields(in); targets[i] = tmp; } Token<BlockTokenIdentifier> accessToken = new Token<BlockTokenIdentifier>(); accessToken.readFields(in); DataOutputStream replyOut = null; // stream to prev target replyOut = new DataOutputStream(NetUtils.getOutputStream(s, datanode.socketWriteTimeout)); if (datanode.isBlockTokenEnabled) { try { datanode.blockTokenSecretManager.checkAccess(accessToken, null, block, BlockTokenSecretManager.AccessMode.WRITE); } catch (InvalidToken e) { try { if (client.length() != 0) { replyOut.writeShort((short) DataTransferProtocol.OP_STATUS_ERROR_ACCESS_TOKEN); Text.writeString(replyOut, datanode.dnRegistration.getName()); replyOut.flush(); } throw new IOException("Access token verification failed, for client " + remoteAddress + " for OP_WRITE_BLOCK for block " + block); } finally { IOUtils.closeStream(replyOut); } } } DataOutputStream mirrorOut = null; // stream to next target DataInputStream mirrorIn = null; // reply from next target Socket mirrorSock = null; // socket to next target BlockReceiver blockReceiver = null; // responsible for data handling String mirrorNode = null; // the name:port of next target String firstBadLink = ""; // first datanode that failed in connection setup short mirrorInStatus = (short) DataTransferProtocol.OP_STATUS_SUCCESS; try { // open a block receiver and check if the block does not exist blockReceiver = new BlockReceiver(block, in, s.getRemoteSocketAddress().toString(), s.getLocalSocketAddress().toString(), isRecovery, client, srcDataNode, datanode); // // Open network conn to backup machine, if // appropriate // if (targets.length > 0) { InetSocketAddress mirrorTarget = null; // Connect to backup machine mirrorNode = targets[0].getName(); mirrorTarget = NetUtils.createSocketAddr(mirrorNode); mirrorSock = datanode.newSocket(); try { int timeoutValue = datanode.socketTimeout + (HdfsConstants.READ_TIMEOUT_EXTENSION * numTargets); int writeTimeout = datanode.socketWriteTimeout + (HdfsConstants.WRITE_TIMEOUT_EXTENSION * numTargets); NetUtils.connect(mirrorSock, mirrorTarget, timeoutValue); mirrorSock.setSoTimeout(timeoutValue); mirrorSock.setSendBufferSize(DEFAULT_DATA_SOCKET_SIZE); mirrorOut = new DataOutputStream(new BufferedOutputStream( NetUtils.getOutputStream(mirrorSock, writeTimeout), SMALL_BUFFER_SIZE)); mirrorIn = new DataInputStream(NetUtils.getInputStream(mirrorSock)); // Write header: Copied from DFSClient.java! mirrorOut.writeShort(DataTransferProtocol.DATA_TRANSFER_VERSION); mirrorOut.write(DataTransferProtocol.OP_WRITE_BLOCK); mirrorOut.writeLong(block.getBlockId()); mirrorOut.writeLong(block.getGenerationStamp()); mirrorOut.writeInt(pipelineSize); mirrorOut.writeBoolean(isRecovery); Text.writeString(mirrorOut, client); mirrorOut.writeBoolean(hasSrcDataNode); if (hasSrcDataNode) { // pass src node information srcDataNode.write(mirrorOut); } mirrorOut.writeInt(targets.length - 1); for (int i = 1; i < targets.length; i++) { targets[i].write(mirrorOut); } accessToken.write(mirrorOut); blockReceiver.writeChecksumHeader(mirrorOut); mirrorOut.flush(); // read connect ack (only for clients, not for replication req) if (client.length() != 0) { mirrorInStatus = mirrorIn.readShort(); firstBadLink = Text.readString(mirrorIn); if (LOG.isDebugEnabled() || mirrorInStatus != DataTransferProtocol.OP_STATUS_SUCCESS) { LOG.info("Datanode " + targets.length + " got response for connect ack " + " from downstream datanode with firstbadlink as " + firstBadLink); } } } catch (IOException e) { if (client.length() != 0) { replyOut.writeShort((short) DataTransferProtocol.OP_STATUS_ERROR); Text.writeString(replyOut, mirrorNode); replyOut.flush(); } IOUtils.closeStream(mirrorOut); mirrorOut = null; IOUtils.closeStream(mirrorIn); mirrorIn = null; IOUtils.closeSocket(mirrorSock); mirrorSock = null; if (client.length() > 0) { throw e; } else { LOG.info(datanode.dnRegistration + ":Exception transfering block " + block + " to mirror " + mirrorNode + ". continuing without the mirror.\n" + StringUtils.stringifyException(e)); } } } // send connect ack back to source (only for clients) if (client.length() != 0) { if (LOG.isDebugEnabled() || mirrorInStatus != DataTransferProtocol.OP_STATUS_SUCCESS) { LOG.info("Datanode " + targets.length + " forwarding connect ack to upstream firstbadlink is " + firstBadLink); } replyOut.writeShort(mirrorInStatus); Text.writeString(replyOut, firstBadLink); replyOut.flush(); } // receive the block and mirror to the next target String mirrorAddr = (mirrorSock == null) ? null : mirrorNode; blockReceiver.receiveBlock(mirrorOut, mirrorIn, replyOut, mirrorAddr, null, targets.length); // if this write is for a replication request (and not // from a client), then confirm block. For client-writes, // the block is finalized in the PacketResponder. if (client.length() == 0) { datanode.notifyNamenodeReceivedBlock(block, DataNode.EMPTY_DEL_HINT); LOG.info("Received block " + block + " src: " + remoteAddress + " dest: " + localAddress + " of size " + block.getNumBytes()); } if (datanode.blockScanner != null) { datanode.blockScanner.addBlock(block); } } catch (IOException ioe) { LOG.info("writeBlock " + block + " received exception " + ioe); throw ioe; } finally { // close all opened streams IOUtils.closeStream(mirrorOut); IOUtils.closeStream(mirrorIn); IOUtils.closeStream(replyOut); IOUtils.closeSocket(mirrorSock); IOUtils.closeStream(blockReceiver); } }
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 .j a v a2 s . 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 . j av a2 s . c om*/ * @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; }