List of usage examples for java.io DataInputStream readLong
public final long readLong() throws IOException
readLong
method of DataInput
. From source file:net.minecraftforge.fml.repackage.com.nothome.delta.GDiffPatcher.java
/** * Patches to an output stream./*from ww w . j av a2 s . c om*/ */ public void patch(SeekableSource source, InputStream patch, OutputStream out) throws IOException { DataOutputStream outOS = new DataOutputStream(out); DataInputStream patchIS = new DataInputStream(patch); // the magic string is 'd1 ff d1 ff' + the version number if (patchIS.readUnsignedByte() != 0xd1 || patchIS.readUnsignedByte() != 0xff || patchIS.readUnsignedByte() != 0xd1 || patchIS.readUnsignedByte() != 0xff || patchIS.readUnsignedByte() != 0x04) { throw new PatchException("magic string not found, aborting!"); } while (true) { int command = patchIS.readUnsignedByte(); if (command == EOF) break; int length; int offset; if (command <= DATA_MAX) { append(command, patchIS, outOS); continue; } switch (command) { case DATA_USHORT: // ushort, n bytes following; append length = patchIS.readUnsignedShort(); append(length, patchIS, outOS); break; case DATA_INT: // int, n bytes following; append length = patchIS.readInt(); append(length, patchIS, outOS); break; case COPY_USHORT_UBYTE: offset = patchIS.readUnsignedShort(); length = patchIS.readUnsignedByte(); copy(offset, length, source, outOS); break; case COPY_USHORT_USHORT: offset = patchIS.readUnsignedShort(); length = patchIS.readUnsignedShort(); copy(offset, length, source, outOS); break; case COPY_USHORT_INT: offset = patchIS.readUnsignedShort(); length = patchIS.readInt(); copy(offset, length, source, outOS); break; case COPY_INT_UBYTE: offset = patchIS.readInt(); length = patchIS.readUnsignedByte(); copy(offset, length, source, outOS); break; case COPY_INT_USHORT: offset = patchIS.readInt(); length = patchIS.readUnsignedShort(); copy(offset, length, source, outOS); break; case COPY_INT_INT: offset = patchIS.readInt(); length = patchIS.readInt(); copy(offset, length, source, outOS); break; case COPY_LONG_INT: long loffset = patchIS.readLong(); length = patchIS.readInt(); copy(loffset, length, source, outOS); break; default: throw new IllegalStateException("command " + command); } } outOS.flush(); }
From source file:ClassFile.java
public boolean read(DataInputStream dis) throws IOException { int len;/*w w w. ja va 2s . com*/ char c; type = dis.readByte(); switch (type) { case CLASS: name = "Class"; index1 = dis.readShort(); index2 = -1; break; case FIELDREF: name = "Field Reference"; index1 = dis.readShort(); index2 = dis.readShort(); break; case METHODREF: name = "Method Reference"; index1 = dis.readShort(); index2 = dis.readShort(); break; case INTERFACE: name = "Interface Method Reference"; index1 = dis.readShort(); index2 = dis.readShort(); break; case NAMEANDTYPE: name = "Name and Type"; index1 = dis.readShort(); index2 = dis.readShort(); break; case STRING: name = "String"; index1 = dis.readShort(); index2 = -1; break; case INTEGER: name = "Integer"; intValue = dis.readInt(); break; case FLOAT: name = "Float"; floatValue = dis.readFloat(); break; case LONG: name = "Long"; longValue = dis.readLong(); break; case DOUBLE: name = "Double"; doubleValue = dis.readDouble(); break; case ASCIZ: case UNICODE: if (type == ASCIZ) name = "ASCIZ"; else name = "UNICODE"; StringBuffer xxBuf = new StringBuffer(); len = dis.readShort(); while (len > 0) { c = (char) (dis.readByte()); xxBuf.append(c); len--; } strValue = xxBuf.toString(); break; default: System.out.println("Warning bad type."); } return (true); }
From source file:se.llbit.chunky.renderer.scene.Scene.java
public synchronized void loadDump(RenderContext context, RenderStatusListener renderListener) { String fileName = name + ".dump"; DataInputStream in = null; try {/*from ww w .ja v a2 s . c om*/ in = new DataInputStream(new GZIPInputStream(context.getSceneFileInputStream(fileName))); String task = "Loading render dump"; renderListener.setProgress(task, 1, 0, 2); Log.info("Loading render dump " + fileName); int dumpWidth = in.readInt(); int dumpHeight = in.readInt(); if (dumpWidth != width || dumpHeight != height) { Log.warn("Render dump discarded: incorrect width or height!"); in.close(); return; } spp = in.readInt(); renderTime = in.readLong(); // Update render status renderListener.setSPP(spp); renderListener.setRenderTime(renderTime); long totalSamples = spp * ((long) (width * height)); renderListener.setSamplesPerSecond((int) (totalSamples / (renderTime / 1000.0))); for (int x = 0; x < width; ++x) { renderListener.setProgress(task, x + 1, 0, width); for (int y = 0; y < height; ++y) { samples[(y * width + x) * 3 + 0] = in.readDouble(); samples[(y * width + x) * 3 + 1] = in.readDouble(); samples[(y * width + x) * 3 + 2] = in.readDouble(); finalizePixel(x, y); } } Log.info("Render dump loaded"); } catch (IOException e) { Log.info("Render dump not loaded"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:se.llbit.chunky.renderer.scene.Scene.java
/** * Merge a render dump into this scene/*from w ww . j a va2 s . c om*/ * @param dumpFile * @param renderListener */ public void mergeDump(File dumpFile, RenderStatusListener renderListener) { int dumpSpp; long dumpTime; DataInputStream in = null; try { in = new DataInputStream(new GZIPInputStream(new FileInputStream(dumpFile))); String task = "Merging render dump"; renderListener.setProgress(task, 1, 0, 2); Log.info("Loading render dump " + dumpFile.getAbsolutePath()); int dumpWidth = in.readInt(); int dumpHeight = in.readInt(); if (dumpWidth != width || dumpHeight != height) { Log.warn("Render dump discarded: incorrect widht or height!"); in.close(); return; } dumpSpp = in.readInt(); dumpTime = in.readLong(); double sa = spp / (double) (spp + dumpSpp); double sb = 1 - sa; for (int x = 0; x < width; ++x) { renderListener.setProgress(task, x + 1, 0, width); for (int y = 0; y < height; ++y) { samples[(y * width + x) * 3 + 0] = samples[(y * width + x) * 3 + 0] * sa + in.readDouble() * sb; samples[(y * width + x) * 3 + 1] = samples[(y * width + x) * 3 + 1] * sa + in.readDouble() * sb; samples[(y * width + x) * 3 + 2] = samples[(y * width + x) * 3 + 2] * sa + in.readDouble() * sb; finalizePixel(x, y); } } Log.info("Render dump loaded"); // Update render status spp += dumpSpp; renderTime += dumpTime; renderListener.setSPP(spp); renderListener.setRenderTime(renderTime); long totalSamples = spp * ((long) (width * height)); renderListener.setSamplesPerSecond((int) (totalSamples / (renderTime / 1000.0))); } catch (IOException e) { Log.info("Render dump not loaded"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } } }
From source file:org.apache.xmlgraphics.image.codec.png.PNGImageDecoder.java
public PNGImage(final InputStream inStream, final PNGDecodeParam inDecodeParam) { final InputStream stream; final PNGDecodeParam decodeParam; if (!inStream.markSupported()) { stream = new BufferedInputStream(inStream); } else {/*from w ww. ja v a2 s . com*/ stream = inStream; } DataInputStream distream = null; try { distream = new DataInputStream(stream); if (inDecodeParam == null) { decodeParam = new PNGDecodeParam(); } else { decodeParam = inDecodeParam; } this.decodeParam = decodeParam; // Get parameter values this.suppressAlpha = decodeParam.getSuppressAlpha(); this.expandPalette = decodeParam.getExpandPalette(); this.output8BitGray = decodeParam.getOutput8BitGray(); this.expandGrayAlpha = decodeParam.getExpandGrayAlpha(); if (decodeParam.getPerformGammaCorrection()) { this.userExponent = decodeParam.getUserExponent(); this.displayExponent = decodeParam.getDisplayExponent(); this.performGammaCorrection = true; this.output8BitGray = true; } this.generateEncodeParam = decodeParam.getGenerateEncodeParam(); if (this.emitProperties) { this.properties.put("file_type", "PNG v. 1.0"); } try { final long magic = distream.readLong(); if (magic != PNG_SIGNATURE) { final String msg = PropertyUtil.getString("PNGImageDecoder0"); throw new RuntimeException(msg); } } catch (final IOException ioe) { log.error("IOException", ioe); final String msg = PropertyUtil.getString("PNGImageDecoder1"); throw new RuntimeException(msg); } do { try { PNGChunk chunk; final String chunkType = PNGChunk.getChunkType(distream); if (chunkType.equals(PNGChunk.ChunkType.IHDR.name())) { chunk = PNGChunk.readChunk(distream); parse_IHDR_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.PLTE.name())) { chunk = PNGChunk.readChunk(distream); parse_PLTE_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.IDAT.name())) { chunk = PNGChunk.readChunk(distream); this.streamVec.add(new ByteArrayInputStream(chunk.getData())); } else if (chunkType.equals(PNGChunk.ChunkType.IEND.name())) { chunk = PNGChunk.readChunk(distream); parse_IEND_chunk(chunk); break; // fall through to the bottom } else if (chunkType.equals(PNGChunk.ChunkType.bKGD.name())) { chunk = PNGChunk.readChunk(distream); parse_bKGD_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.cHRM.name())) { chunk = PNGChunk.readChunk(distream); parse_cHRM_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.gAMA.name())) { chunk = PNGChunk.readChunk(distream); parse_gAMA_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.hIST.name())) { chunk = PNGChunk.readChunk(distream); parse_hIST_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.iCCP.name())) { chunk = PNGChunk.readChunk(distream); parse_iCCP_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.pHYs.name())) { chunk = PNGChunk.readChunk(distream); parse_pHYs_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.sBIT.name())) { chunk = PNGChunk.readChunk(distream); parse_sBIT_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.sRGB.name())) { chunk = PNGChunk.readChunk(distream); parse_sRGB_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.tEXt.name())) { chunk = PNGChunk.readChunk(distream); parse_tEXt_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.tIME.name())) { chunk = PNGChunk.readChunk(distream); parse_tIME_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.tRNS.name())) { chunk = PNGChunk.readChunk(distream); parse_tRNS_chunk(chunk); } else if (chunkType.equals(PNGChunk.ChunkType.zTXt.name())) { chunk = PNGChunk.readChunk(distream); parse_zTXt_chunk(chunk); } else { chunk = PNGChunk.readChunk(distream); // Output the chunk data in raw form final String type = chunk.getTypeString(); final byte[] data = chunk.getData(); if (this.encodeParam != null) { this.encodeParam.addPrivateChunk(type, data); } if (this.emitProperties) { final String key = "chunk_" + this.chunkIndex++ + ':' + type; this.properties.put(key.toLowerCase(), data); } } } catch (final Exception e) { log.error("Exception", e); final String msg = PropertyUtil.getString("PNGImageDecoder2"); throw new RuntimeException(msg); } } while (true); // Final post-processing if (this.significantBits == null) { this.significantBits = new int[this.inputBands]; for (int i = 0; i < this.inputBands; ++i) { this.significantBits[i] = this.bitDepth; } if (this.emitProperties) { this.properties.put("significant_bits", this.significantBits); } } } finally { IOUtils.closeQuietly(distream); } }
From source file:com.ocpsoft.pretty.faces.config.annotation.ByteCodeAnnotationFilter.java
/** * <p>// ww w. j a v a 2 s . co m * Checks whether that supplied {@link InputStream} contains a Java class * file that might contain PrettyFaces annotations. * </p> * <p> * The caller of this method is responsible to close the supplied * {@link InputStream}. This method won't do it! * </p> * * @param classFileStream * The stream to read the class file from. * @return <code>true</code> for files that should be further checked for * annotations * @throws IOException * for any kind of IO problem */ @SuppressWarnings("unused") public boolean accept(InputStream classFileStream) throws IOException { // open a DataInputStream DataInputStream in = new DataInputStream(classFileStream); // read magic and abort if it doesn't match int magic = in.readInt(); if (magic != CLASS_FILE_MAGIC) { if (log.isDebugEnabled()) { log.debug("Magic not found! Not a valid class file!"); } return false; } // check for at least JDK 1.5 int minor = in.readUnsignedShort(); int major = in.readUnsignedShort(); if (major < 49) { // JDK 1.4 or less if (log.isTraceEnabled()) { log.trace("Not a JDK5 class! It cannot contain annotations!"); } return false; } // this values is equal to the number entries in the constants pool + 1 int constantPoolEntries = in.readUnsignedShort() - 1; // loop over all entries in the constants pool for (int i = 0; i < constantPoolEntries; i++) { // the tag to identify the record type int tag = in.readUnsignedByte(); // process record according to its type switch (tag) { case CONSTANT_Class: /* * CONSTANT_Class_info { * u1 tag; * u2 name_index; * } */ in.readUnsignedShort(); break; case CONSTANT_Fieldref: case CONSTANT_Methodref: case CONSTANT_InterfaceMethodref: /* * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info { * u1 tag; * u2 class_index; * u2 name_and_type_index; * } */ in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_String: /* * CONSTANT_String_info { * u1 tag; * u2 string_index; * } */ in.readUnsignedShort(); break; case CONSTANT_Integer: case CONSTANT_Float: /* * CONSTANT_[Integer|Float]_info { * u1 tag; * u4 bytes; * } */ in.readInt(); break; case CONSTANT_Long: case CONSTANT_Double: /* * CONSTANT_Long_info { * u1 tag; * u4 high_bytes; * u4 low_bytes; * } */ in.readLong(); /* * We must increase the constant pool index because this tag * type takes two entries */ i++; break; case CONSTANT_NameAndType: /* * CONSTANT_NameAndType_info { * u1 tag; * u2 name_index; * u2 descriptor_index; * } */ in.readUnsignedShort(); in.readUnsignedShort(); break; case CONSTANT_Utf8: /* * CONSTANT_Utf8_info { * u1 tag; * u2 length; * u1 bytes[length]; * } */ String str = in.readUTF(); // check if this string sounds interesting if (str.contains(SEARCH_STRING)) { if (log.isTraceEnabled()) { log.trace("Found PrettyFaces annotation reference in constant pool: " + str); } return true; } break; default: /* * Unknown tag! Should not happen! We will scan the class in this case. */ if (log.isDebugEnabled()) { log.debug("Unknown constant pool tag found: " + tag); } return true; } } /* * We are finished with reading the interesting parts of the class file. * We stop here because the file doesn't seem to be interesting. */ if (log.isTraceEnabled()) { log.trace("No reference to PrettyFaces annotations found!"); } return false; }
From source file:org.apache.xmlgraphics.image.codec.png.PNGRed.java
public PNGRed(final InputStream inStream, final PNGDecodeParam inDecodeParam) { final InputStream stream; if (!inStream.markSupported()) { stream = new BufferedInputStream(inStream); } else {// w w w. j av a2s . c om stream = inStream; } DataInputStream distream = null; try { distream = new DataInputStream(stream); final PNGDecodeParam decodeParam; if (inDecodeParam == null) { decodeParam = new PNGDecodeParam(); } else { decodeParam = inDecodeParam; } this.decodeParam = decodeParam; // Get parameter values this.suppressAlpha = decodeParam.getSuppressAlpha(); this.expandPalette = decodeParam.getExpandPalette(); this.output8BitGray = decodeParam.getOutput8BitGray(); this.expandGrayAlpha = decodeParam.getExpandGrayAlpha(); if (decodeParam.getPerformGammaCorrection()) { this.userExponent = decodeParam.getUserExponent(); this.displayExponent = decodeParam.getDisplayExponent(); this.performGammaCorrection = true; this.output8BitGray = true; } this.generateEncodeParam = decodeParam.getGenerateEncodeParam(); if (this.emitProperties) { this.properties.put("file_type", "PNG v. 1.0"); } try { final long magic = distream.readLong(); if (magic != 0x89504e470d0a1a0aL) { final String msg = PropertyUtil.getString("PNGImageDecoder0"); throw new RuntimeException(msg); } } catch (final Exception e) { log.error("Exception", e); final String msg = PropertyUtil.getString("PNGImageDecoder1"); throw new RuntimeException(msg); } do { try { PNGChunk chunk; final String chunkType = getChunkType(distream); if (chunkType.equals("IHDR")) { chunk = readChunk(distream); parse_IHDR_chunk(chunk); } else if (chunkType.equals("PLTE")) { chunk = readChunk(distream); parse_PLTE_chunk(chunk); } else if (chunkType.equals("IDAT")) { chunk = readChunk(distream); this.streamVec.add(new ByteArrayInputStream(chunk.getData())); } else if (chunkType.equals("IEND")) { chunk = readChunk(distream); parse_IEND_chunk(chunk); break; // fall through to the bottom } else if (chunkType.equals("bKGD")) { chunk = readChunk(distream); parse_bKGD_chunk(chunk); } else if (chunkType.equals("cHRM")) { chunk = readChunk(distream); parse_cHRM_chunk(chunk); } else if (chunkType.equals("gAMA")) { chunk = readChunk(distream); parse_gAMA_chunk(chunk); } else if (chunkType.equals("hIST")) { chunk = readChunk(distream); parse_hIST_chunk(chunk); } else if (chunkType.equals("iCCP")) { chunk = readChunk(distream); parse_iCCP_chunk(chunk); } else if (chunkType.equals("pHYs")) { chunk = readChunk(distream); parse_pHYs_chunk(chunk); } else if (chunkType.equals("sBIT")) { chunk = readChunk(distream); parse_sBIT_chunk(chunk); } else if (chunkType.equals("sRGB")) { chunk = readChunk(distream); parse_sRGB_chunk(chunk); } else if (chunkType.equals("tEXt")) { chunk = readChunk(distream); parse_tEXt_chunk(chunk); } else if (chunkType.equals("tIME")) { chunk = readChunk(distream); parse_tIME_chunk(chunk); } else if (chunkType.equals("tRNS")) { chunk = readChunk(distream); parse_tRNS_chunk(chunk); } else if (chunkType.equals("zTXt")) { chunk = readChunk(distream); parse_zTXt_chunk(chunk); } else { chunk = readChunk(distream); // Output the chunk data in raw form final String type = chunk.getTypeString(); final byte[] data = chunk.getData(); if (this.encodeParam != null) { this.encodeParam.addPrivateChunk(type, data); } if (this.emitProperties) { final String key = "chunk_" + this.chunkIndex++ + ':' + type; this.properties.put(key.toLowerCase(), data); } } } catch (final Exception e) { log.error("Exception", e); final String msg = PropertyUtil.getString("PNGImageDecoder2"); throw new RuntimeException(msg); } } while (true); // Final post-processing if (this.significantBits == null) { this.significantBits = new int[this.inputBands]; for (int i = 0; i < this.inputBands; ++i) { this.significantBits[i] = this.bitDepth; } if (this.emitProperties) { this.properties.put("significant_bits", this.significantBits); } } } finally { IOUtils.closeQuietly(distream); IOUtils.closeQuietly(stream); } }
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 www . jav a 2 s .com*/ * @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//from w w w . j ava2s . co 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 ww w . j a v a 2 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 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; }