/// <summary> /// Checks whether an {@link InputStream} is in the Horrible /// Property Set Format. /// </summary> /// <param name="stream">The {@link InputStream} To check. In order To /// perform the check, the method Reads the first bytes from the /// stream. After Reading, the stream is Reset To the position it /// had before Reading. The {@link InputStream} must support the /// {@link InputStream#mark} method.</param> /// <returns> /// <c>true</c> if the stream is a property Set /// stream; otherwise, <c>false</c>. /// </returns> public static bool IsPropertySetStream(Stream stream) { ByteArrayInputStream dis = stream as ByteArrayInputStream; /* * Read at most this many bytes. */ int BUFFER_SIZE = 50; /* * Mark the current position in the stream so that we can * Reset To this position if the stream does not contain a * property Set. */ if (dis == null || !dis.MarkSupported()) { throw new MarkUnsupportedException(stream.GetType().Name); } dis.Mark(BUFFER_SIZE); /* * Read a couple of bytes from the stream. */ byte[] buffer = new byte[BUFFER_SIZE]; int bytes = stream.Read(buffer, 0, (int)Math.Min(buffer.Length, dis.Available())); bool isPropertySetStream = IsPropertySetStream(buffer, 0, bytes); stream.Seek(0, SeekOrigin.Begin); dis.Reset(); return(isPropertySetStream); }