public byte[] StreamToByte(System.IO.Stream Stream) { Int32 length = Stream.Length > Int32.MaxValue ? Int32.MaxValue : Convert.ToInt32(Stream.Length); Byte[] buffer = new Byte[length]; Stream.Read(buffer, 0, length); return buffer; }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "usage": Usage = reader.ReadContentAsInt(); break; case "predicate": PredicateName = reader.Value; break; case "namespace": NamespaceName = reader.Value; break; case "first_added": DateFirstAdded = UtilityMethods.UnixTimestampToDate(reader.Value); break; case "last_added": DateLastUsed = UtilityMethods.UnixTimestampToDate(reader.Value); break; } } reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) ValueText = reader.ReadContentAsString(); reader.Read(); }
public override bool Supports(System.IO.Stream stream, long inLength) { long startPosition = stream.Position; try { int firstByte = stream.ReadByte(); if (firstByte != this.magicByte) return false; // no need to read the size info as well if it's used anyway. if (!SkipLargePlaintexts) return true; byte[] sizeBytes = new byte[3]; stream.Read(sizeBytes, 0, 3); int outSize = IOUtils.ToNDSu24(sizeBytes, 0); if (outSize == 0) { sizeBytes = new byte[4]; stream.Read(sizeBytes, 0, 4); outSize = (int)IOUtils.ToNDSu32(sizeBytes, 0); } return outSize <= MaxPlaintextSize; } finally { stream.Position = startPosition; } }
internal bool InitializeSizeAndName(System.IO.FileStream fs) { Buffer = new byte[8]; var bytesRead = fs.Read(Buffer, 0, Buffer.Length); if (bytesRead < Buffer.Length) { return false; } Size = GetUInt(0); Name = GetString(4, 4); if (Size == 0) { Size = (UInt64)(fs.Length - fs.Position); } if (Size == 1) { bytesRead = fs.Read(Buffer, 0, Buffer.Length); if (bytesRead < Buffer.Length) { return false; } Size = GetUInt64(0) - 8; } Position = ((ulong)(fs.Position)) + Size - 8; return true; }
public override DecodedObject<object> decodeAny(DecodedObject<object> decodedTag, System.Type objectClass, ElementInfo elementInfo, System.IO.Stream stream) { int bufSize = elementInfo.MaxAvailableLen; if (bufSize == 0) return null; System.IO.MemoryStream anyStream = new System.IO.MemoryStream(1024); /*int tagValue = (int)decodedTag.Value; for (int i = 0; i < decodedTag.Size; i++) { anyStream.WriteByte((byte)tagValue); tagValue = tagValue >> 8; }*/ if(bufSize<0) bufSize = 1024; int len = 0; if (bufSize > 0) { byte[] buffer = new byte[bufSize]; int readed = stream.Read(buffer, 0, buffer.Length); while (readed > 0) { anyStream.Write(buffer, 0, readed); len += readed; if (elementInfo.MaxAvailableLen > 0) break; readed = stream.Read(buffer, 0, buffer.Length); } } CoderUtils.checkConstraints(len, elementInfo); return new DecodedObject<object>(anyStream.ToArray(), len); }
/// <summary> /// Returns a uint value CRC of a file /// </summary> /// <param name="stream"></param> /// <returns>uint crc32</returns> public uint GetCrc32(System.IO.Stream stream) { unchecked { uint crc32Result; crc32Result = 0xFFFFFFFF; byte[] buffer = new byte[BUFFER_SIZE]; int readSize = BUFFER_SIZE; int count = stream.Read(buffer, 0, readSize); while (count > 0) { for (int i = 0; i < count; i++) { crc32Result = ((crc32Result) >> 8) ^ crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)]; } count = stream.Read(buffer, 0, readSize); if (PercentCompleteChange != null) PercentCompleteChange(this, new ProgressChangeEventArgs((int)((stream.Position * 100) / stream.Length), stream.Position, stream.Length)); } stream.Close(); return ~crc32Result; } }
/// <summary> /// Returns the CRC32 for the specified stream, and writes the input into the output stream. /// </summary> /// <param name="input">The stream over which to calculate the CRC32</param> /// <param name="output">The stream into which to deflate the input</param> /// <returns>the CRC32 calculation</returns> public UInt32 GetCrc32AndCopy(System.IO.Stream input, System.IO.Stream output) { unchecked { UInt32 crc32Result; crc32Result = 0xFFFFFFFF; byte[] buffer = new byte[BUFFER_SIZE]; int readSize = BUFFER_SIZE; _TotalBytesRead= 0; int count = input.Read(buffer, 0, readSize); if (output != null) output.Write(buffer,0,count); _TotalBytesRead += count; while (count > 0) { for (int i = 0; i < count; i++) { crc32Result = ((crc32Result) >> 8) ^ crc32Table[(buffer[i]) ^ ((crc32Result) & 0x000000FF)]; } count = input.Read(buffer, 0, readSize); if (output != null) output.Write(buffer,0,count); _TotalBytesRead += count; } return ~crc32Result; } }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "usage": Usage = reader.ReadContentAsInt(); break; case "predicate": PredicateName = reader.Value; break; case "namespace": NamespaceName = reader.Value; break; } } reader.Read(); if (reader.NodeType == System.Xml.XmlNodeType.Text) PairName = reader.ReadContentAsString(); reader.Read(); }
private static bool VerifySignature(System.IO.Stream stream, System.Security.Cryptography.RSACryptoServiceProvider key) { stream.Position = 0; var signature = new byte[SIGNED_HASH_SIZE]; if (stream.Read(signature, 0, signature.Length) != signature.Length) throw new System.IO.InvalidDataException("Unexpected end-of-stream while reading signature"); var sha256 = System.Security.Cryptography.SHA256.Create(); sha256.Initialize(); var bytes = stream.Length - (signature.Length); var buf = new byte[8 * 1024]; while (bytes > 0) { var r = stream.Read(buf, 0, (int)Math.Min(bytes, buf.Length)); if (r == 0) throw new Exception("Unexpected end-of-stream while reading content"); bytes -= r; sha256.TransformBlock(buf, 0, r, buf, 0); } sha256.TransformFinalBlock(buf, 0, 0); var hash = sha256.Hash; var OID = System.Security.Cryptography.CryptoConfig.MapNameToOID("SHA256"); return key.VerifyHash(hash, OID, signature); }
public override AbstractToken ScanToken(System.IO.StringReader sr) { sr.Read(); string accum = ""; while ('"' != (char)sr.Peek() && sr.Peek() != -1) { accum += (char)sr.Read(); } return new TokenStringLiteral(accum); }
private static object ReadNull(System.IO.TextReader reader) { EatWhiteSpace(reader); var ch = (char)reader.Peek(); if (ch == 'n') { reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read chars n,u,l,l } return null; }
unsafe public static object Load(System.Runtime.InteropServices.ComTypes.IStream stream) { // Exit if Stream is NULL if (stream == null) { return null; } // Get Pointer to Int32 int cb; int* pcb = &cb; // Get Size of the object's Byte Array byte[] arrLen = new Byte[4]; stream.Read(arrLen, arrLen.Length, new IntPtr(pcb)); cb = BitConverter.ToInt32(arrLen, 0); // Read the object's Byte Array byte[] bytes = new byte[cb]; stream.Read(bytes, cb, new IntPtr(pcb)); if (bytes.Length != cb) throw new Exception("Error reading object from stream"); // Deserialize byte array AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); object data = null; MemoryStream memoryStream = new MemoryStream(bytes); BinaryFormatter binaryFormatter = new BinaryFormatter(); object objectDeserialize = binaryFormatter.Deserialize(memoryStream); if (objectDeserialize != null) { data = objectDeserialize; } memoryStream.Close(); AppDomain.CurrentDomain.AssemblyResolve -= new ResolveEventHandler(PeristStreamHelper.ResolveEventHandler); //deserialize ArcObjects if (data is string) { string str = (string)data; if (str.IndexOf("http://www.esri.com/schemas/ArcGIS/9.2") != -1) { IXMLStream readerStream = new XMLStreamClass(); readerStream.LoadFromString(str); IXMLReader xmlReader = new XMLReaderClass(); xmlReader.ReadFrom((IStream)readerStream); IXMLSerializer xmlReadSerializer = new XMLSerializerClass(); object retObj = xmlReadSerializer.ReadObject(xmlReader, null, null); if (null != retObj) data = retObj; } } return data; }
public override void ReadXml(System.Xml.XmlReader reader) { reader.ReadStartElement(); while (reader.IsStartElement()) { reader.Read(); } reader.Read(); }
public static void CopyStream(System.IO.Stream fromStream, System.IO.Stream toStream) { int Length = 65536; Byte[] buffer = new Byte[Length]; int bytesRead = fromStream.Read(buffer, 0, Length); while (bytesRead > 0) { toStream.Write(buffer, 0, bytesRead); bytesRead = fromStream.Read(buffer, 0, Length); } }
protected override void Inner_Read_Data(System.Xml.XmlTextReader XMLReader) { while (XMLReader.Read()) { if ((XMLReader.NodeType == XmlNodeType.Element) && (XMLReader.Name.ToLower() == "value")) { XMLReader.Read(); html_text = XMLReader.Value.Trim(); } } }
static void CopyStream(System.IO.Stream src, System.IO.Stream dest) { byte[] buffer = new byte[1024]; int len = src.Read(buffer, 0, buffer.Length); while (len > 0) { dest.Write(buffer, 0, len); len = src.Read(buffer, 0, buffer.Length); } dest.Flush(); }
public ArraySegment<byte> GetData(System.IO.Stream stream,byte[] buffer) { Seek(stream); byte[] lendata = new byte[4]; stream.Read(lendata, 0, 4); int length = BitConverter.ToInt32(lendata,0); if (length > 0) { stream.Read(buffer, 0, length); } return new ArraySegment<byte>(buffer, 0, length); }
void IFlickrParsable.Load(System.Xml.XmlReader reader) { while (reader.MoveToNextAttribute()) { switch (reader.LocalName) { case "nsid": InstitutionId = reader.Value; break; case "date_launch": DateLaunched = UtilityMethods.UnixTimestampToDate(reader.Value); break; default: UtilityMethods.CheckParsingException(reader); break; } } reader.Read(); while (reader.NodeType != System.Xml.XmlNodeType.EndElement) { switch (reader.LocalName) { case "name": InstitutionName = reader.ReadElementContentAsString(); break; case "urls": reader.Read(); while (reader.LocalName == "url") { string type = reader.GetAttribute("type"); string url = reader.ReadElementContentAsString(); switch (type) { case "site": SiteUrl = url; break; case "flickr": FlickrUrl = url; break; case "license": LicenseUrl = url; break; } } reader.Read(); break; } } reader.Read(); }
internal static JsonBase Parse(System.IO.TextReader json) { JsonCustomArray result = new JsonCustomArray(); while (json.Peek() != ']') { char comma = (char)json.Read(); System.Diagnostics.Debug.Assert(comma == ',' || comma == '['); result.Properties.Add(JsonBase.BaseParse(json)); } char close = (char)json.Read(); System.Diagnostics.Debug.Assert(close == ']'); return result; }
public override void ReadXml(System.Xml.XmlReader reader) { reader.MoveToContent(); reader.Read(); while (reader.LocalName != "achievements") { var message = ServerMessageFactory.Instance.ConstructMessage(reader.LocalName); message.ReadXml(reader); achievementList.Add(message); reader.Read(); } }
public override void ReadXml(System.Xml.XmlReader reader) { reader.MoveToContent(); messageName = reader.LocalName; reader.Read(); while (reader.LocalName != "visibleVertices") { var message = ServerMessageFactory.Instance.ConstructMessage(reader.LocalName); message.ReadXml(reader); visibleVertices.Add(message); reader.Read(); } }
public static void ReadToBuf(System.IO.Stream s, byte[] buf, int offset, int count) { int read_offset = offset; int len = s.Read(buf, read_offset, count - (read_offset - offset)); read_offset += len; while (read_offset < offset + count && len > 0) { len = s.Read(buf, read_offset, count - (read_offset - offset)); read_offset += len; } }
public bool ReadFile(System.IO.Stream stream, bool encoded = true) { byte[] dstBuffer; if (encoded) { byte[] xmlFileData; int fileLen = (int)stream.Length; xmlFileData = new byte[fileLen]; stream.Read(xmlFileData, 0, fileLen); dstBuffer = DatDigger.Crypto.ShuffleString.Decode(xmlFileData, fileLen); string fileData = Encoding.UTF8.GetString(dstBuffer); fileData = null; } else { dstBuffer = new byte[stream.Length]; stream.Position = 0; stream.Read(dstBuffer, 0, (int)stream.Length); } try { using (System.IO.MemoryStream memStream = new System.IO.MemoryStream(dstBuffer)) { var reader = XmlReader.Create(memStream); var doc = new XmlDocument(); doc.Load(reader); var nav = doc.DocumentElement.CreateNavigator(); var sheetElements = nav.SelectChildren("sheet", ns); foreach (XPathNavigator sheet in sheetElements) { Sheet result = ReadSheet(sheet); if (result != null) { this.Sheets.Add(result); } } } if (this.Sheets.Count == 0) { return false; } return true; } catch { return false; } }
public static byte Lex(System.IO.StreamReader code, LexResult into) { var token = ""; byte r; while (!code.EndOfStream) { var c = code.Read(); if (c == '[') { r = AddToken(token, into); token = ""; if (r != 0x00) return r; while (!code.EndOfStream && c != ']') { token += (char)c; c = code.Read(); } if (c != ']') return 0x08; token += ']'; r = AddToken(token, into); token = ""; if (r != 0x00) return r; } else if (c == '.' || c == '\n' || c == '\r') { r = AddToken(token, into); if (r != 0x00) return r; token = ""; } else if (c == ';') { r = AddToken(token, into); token = ""; if (r != 0x00) return r; while (!code.EndOfStream && c != '\n' && c != '\r') c = code.Read(); } else token += (char)c; } r = AddToken(token, into); if (r != 0x00) return r; Console.WriteLine(String.Format("Binary size: {0:X2} bytes.", into.ByteCount)); return 0x00; }
/// <summary> /// /// </summary> /// <param name="reader"></param> /// <returns></returns> public static ABNF_ProseVal Parse(System.IO.StringReader reader) { if(reader == null){ throw new ArgumentNullException("reader"); } /* prose-val = "<" *(%x20-3D / %x3F-7E) ">" ; bracketed string of SP and VCHAR ; without angles ; prose description, to be used as ; last resort */ if(reader.Peek() != '<'){ throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'."); } // Eat "<" reader.Read(); // TODO: *c-wsp StringBuilder value = new StringBuilder(); while(true){ // We reached end of stream, no closing DQUOTE. if(reader.Peek() == -1){ throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'."); } // We have closing ">". else if(reader.Peek() == '>'){ reader.Read(); break; } // Allowed char. else if((reader.Peek() >= 0x20 && reader.Peek() <= 0x3D) || (reader.Peek() >= 0x3F && reader.Peek() <= 0x7E)){ value.Append((char)reader.Read()); } // Invalid value. else{ throw new ParseException("Invalid ABNF 'prose-val' value '" + reader.ReadToEnd() + "'."); } } return new ABNF_ProseVal(value.ToString()); }
private static object ReadBool(System.IO.TextReader reader) { EatWhiteSpace(reader); var ch = (char)reader.Peek(); if (ch == 't') { reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read chars t,r,u,e return true; } reader.Read(); reader.Read(); reader.Read(); reader.Read(); reader.Read(); // read char f,a,l,s,e return false; }
public static byte[] ReadToEnd(System.IO.Stream stream) { long originalPosition = stream.Position; byte[] readBuffer = new byte[4096]; int totalBytesRead = 0; int bytesRead; while ((bytesRead = stream.Read(readBuffer, totalBytesRead, readBuffer.Length - totalBytesRead)) > 0) { totalBytesRead += bytesRead; if (totalBytesRead == readBuffer.Length) { int nextByte = stream.ReadByte(); if (nextByte != -1) { byte[] temp = new byte[readBuffer.Length * 2]; Buffer.BlockCopy(readBuffer, 0, temp, 0, readBuffer.Length); Buffer.SetByte(temp, totalBytesRead, (byte)nextByte); readBuffer = temp; totalBytesRead++; } } } byte[] buffer = readBuffer; if (readBuffer.Length != totalBytesRead) { buffer = new byte[totalBytesRead]; Buffer.BlockCopy(readBuffer, 0, buffer, 0, totalBytesRead); } return buffer; }
private java.io.InputStream GetJavaInputStream(System.IO.Stream stream) { byte[] buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); java.io.ByteArrayInputStream byteStreams = new java.io.ByteArrayInputStream(buffer); return byteStreams; }
/// <summary> /// LĂȘ comando. /// </summary> /// <param name="p_reader">Objeto XML.</param> private void ReadCommand(System.Xml.XmlReader p_reader) { System.Xml.XmlReader v_item; this.v_cmd = new Spartacus.Database.Command(); while (p_reader.Read()) { if (p_reader.IsStartElement()) { switch (p_reader.Name) { case "sql": this.v_cmd.v_text = p_reader.ReadString(); break; case "parameter": v_item = p_reader.ReadSubtree(); this.ReadParameter(v_item); v_item.Close(); break; default: break; } } } }
public void CacheImage(string imageFileName, System.IO.Stream imageStream) { if (!Directory.Exists(cachePath)) Directory.CreateDirectory(cachePath); lock (padlock) { try { using (var output = new FileStream(cachePath + imageFileName, FileMode.Create)) { byte[] buffer = new byte[1024]; int read; if (imageStream != null) while ((read = imageStream.Read(buffer, 0, buffer.Length)) > 0) { output.Write(buffer, 0, read); } } } catch { } } }