@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") private static Control[] loadControls() { Document document; try { // use temporary bytes stream because otherwise inputStreamSkippingBOM will fail // on ZipFileInputStream used in jar files final InputStream stream = HTMLControls.class.getResourceAsStream("HtmlControls.xml"); final byte[] bytes = FileUtilRt.loadBytes(stream); stream.close(); final UnsyncByteArrayInputStream bytesStream = new UnsyncByteArrayInputStream(bytes); document = JDOMUtil.loadDocument(CharsetToolkit.inputStreamSkippingBOM(bytesStream)); bytesStream.close(); } catch (Exception e) { LOG.error(e); return new Control[0]; } if (!document.getRootElement().getName().equals("htmlControls")) { LOG.error("HTMLControls storage is broken"); return new Control[0]; } return XmlSerializer.deserialize(document, Control[].class); }
private void init() { try { final byte[] bytes = FileUtil.loadFileBytes(myFile); final DataInputStream dis = new DataInputStream(new UnsyncByteArrayInputStream(bytes)); final int size = dis.readInt(); for (int i = 0; i < size; i++) { final KeyWrapper<K> keyWrapper = new KeyWrapper<K>(myKeyDescriptor, myKeyDescriptor.read(dis)); final V value = myValueExternalizer.read(dis); myMap.put(keyWrapper, value); } } catch (FileNotFoundException ignore) { } catch (IOException e) { LOG.error(e); } }
@NotNull public Stub getStub(boolean willIndexStub) throws SerializerNotFoundException { Stub stubElement = myStubElement; if (stubElement != null) { // not null myStubElement means we just built SerializedStubTree for indexing, // if we request stub for indexing we can safely use it myStubElement = null; if (willIndexStub) return stubElement; } return SerializationManagerEx.getInstanceEx().deserialize(new UnsyncByteArrayInputStream(myBytes)); }
@Override @Nonnull public InputStream getInputStream() throws IOException { final byte[] preloadedContent = getUserData(ourPreloadedContentKey); return VfsUtilCore.inputStreamSkippingBOM( preloadedContent == null ? ourPersistence.getInputStream(this): new DataInputStream(new UnsyncByteArrayInputStream(preloadedContent)), this ); }
public static <Key, Value> void checkValuesHaveProperEqualsAndHashCode(@Nonnull Map<Key, Value> data, @Nonnull ID<Key, Value> indexId, @Nonnull DataExternalizer<Value> valueExternalizer) { if (DebugAssertions.DEBUG) { for (Map.Entry<Key, Value> e : data.entrySet()) { final Value value = e.getValue(); if (!(Comparing.equal(value, value) && (value == null || value.hashCode() == value.hashCode()))) { LOG.error("Index " + indexId.toString() + " violates equals / hashCode contract for Value parameter"); } try { final BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(); DataOutputStream outputStream = new DataOutputStream(out); valueExternalizer.save(outputStream, value); outputStream.close(); final Value deserializedValue = valueExternalizer.read(new DataInputStream(new UnsyncByteArrayInputStream(out.getInternalBuffer(), 0, out.size()))); if (!(Comparing.equal(value, deserializedValue) && (value == null || value.hashCode() == deserializedValue.hashCode()))) { LOG.error("Index " + indexId.toString() + " deserialization violates equals / hashCode contract for Value parameter"); } } catch (IOException ex) { LOG.error(ex); } } } }
@Nonnull public Stub getStub(boolean willIndexStub) throws SerializerNotFoundException { Stub stubElement = myStubElement; if (stubElement != null) { // not null myStubElement means we just built SerializedStubTree for indexing, // if we request stub for indexing we can safely use it myStubElement = null; if (willIndexStub) return stubElement; } return SerializationManagerEx.getInstanceEx().deserialize(new UnsyncByteArrayInputStream(myBytes)); }
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed") private static Control[] loadControls() { Document document; try { // use temporary bytes stream because otherwise inputStreamSkippingBOM will fail // on ZipFileInputStream used in jar files final InputStream stream = HTMLControls.class.getResourceAsStream("HtmlControls.xml"); final byte[] bytes = FileUtilRt.loadBytes(stream); stream.close(); final UnsyncByteArrayInputStream bytesStream = new UnsyncByteArrayInputStream(bytes); document = JDOMUtil.loadDocument(CharsetToolkit.inputStreamSkippingBOM(bytesStream)); bytesStream.close(); } catch(Exception e) { LOG.error(e); return new Control[0]; } if(!document.getRootElement().getName().equals("htmlControls")) { LOG.error("HTMLControls storage is broken"); return new Control[0]; } return XmlSerializer.deserialize(document, Control[].class); }
@Override public InputStream getInputStream() throws IOException { return new UnsyncByteArrayInputStream(myContent); }
@Override public DataInputStream readStream(int record) throws IOException { if (myDoNotZipCaches) return super.readStream(record); BufferExposingByteArrayOutputStream stream = internalReadStream(record); return new DataInputStream(new UnsyncByteArrayInputStream(stream.getInternalBuffer(), 0, stream.size())); }
public CustomInflaterInputStream(byte[] compressedData) { super(new UnsyncByteArrayInputStream(compressedData), new Inflater(), 1); // force to directly use compressed data, this ensures less round trips with native extraction code and copy streams this.buf = compressedData; this.len = -1; }
public DataInputStream readStream(int record) throws IOException { final byte[] bytes = readBytes(record); return new DataInputStream(new UnsyncByteArrayInputStream(bytes)); }
public DataInputStream readStream(int record) throws IOException { if (myDoNotZipCaches) return super.readStream(record); BufferExposingByteArrayOutputStream stream = internalReadStream(record); return new DataInputStream(new UnsyncByteArrayInputStream(stream.getInternalBuffer(), 0, stream.size())); }