stream

Transform a Scala Stream to a new Stream which is the sum of the current element and the previous element

烂漫一生 提交于 2020-01-13 20:51:28
问题 How to transform a Scala Stream of integers so that we have a new Stream where the elements are the sum of this element and the previous element. By example if the input stream is 1, 2, 3, 4 ... then the output stream is 1, 3, 5, 7. Also a second question, how would you make the sum use the previous one in the output stream so that the output would be 1, (2+(1)), (3+(2+1)), (4+(3+(2+1))). 回答1: Just zip your stream with a shifted version of itself and sum the two elements. val s1 = Stream.from

Reading from a stream with mixed XML and plain text

夙愿已清 提交于 2020-01-13 19:06:23
问题 I have a text stream that contains segments of both arbitrary plain text and well-formed xml elements. How can I read it and extract the xml elements only? XmlReader with ConformanceLevel set to Fragment still throws an exception when it encounters plain text, which to it is malformed xml. Any ideas? Thanks Here's my code so far: XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlReader reader = XmlReader.Create(stream,

Reading from a stream with mixed XML and plain text

吃可爱长大的小学妹 提交于 2020-01-13 19:06:16
问题 I have a text stream that contains segments of both arbitrary plain text and well-formed xml elements. How can I read it and extract the xml elements only? XmlReader with ConformanceLevel set to Fragment still throws an exception when it encounters plain text, which to it is malformed xml. Any ideas? Thanks Here's my code so far: XmlReaderSettings settings = new XmlReaderSettings(); settings.ConformanceLevel = ConformanceLevel.Fragment; using (XmlReader reader = XmlReader.Create(stream,

Windows Phone 8 - Streaming a Podcast MP3 file

左心房为你撑大大i 提交于 2020-01-13 16:55:09
问题 I'm creating an app that reads a single podcast feed (unique to the app) and shows the episode titles in a LongListSelector . I can obtain the MP3 URI for each episode by parsing the RSS file. I'd like to add functionality that, when the user taps an item in the list, the URI is passed to an audio streamer and played like a music file. I saw a tutorial on How to play background audio for Windows Phone, which points me to a project template for streaming audio. I'm just wondering, is it still

Issue with reading file on Windows Phone 8 SD card

和自甴很熟 提交于 2020-01-13 12:12:11
问题 I have problems reads the file on Windows Phone SD card. I get the valid Stream object using ExternalStorageFile.OpenForReadAsync. However any seek operation is ignored and position is not moved although the stream CanSeek property is true; private async void ReadFileOnSDCard(ExternalStorageFile file) { Stream stream = await file.OpenForReadAsync(); using (stream) { long curPos= stream.Seek(100, SeekOrigin.Begin); long pos = stream.Position; // both curPos and pos are 0. 回答1: I was fighting

Is there a good way to stream the results from an external process into a Visual Studio output pane?

与世无争的帅哥 提交于 2020-01-13 11:26:13
问题 I have a custom output pane set up in a VsPackage similar to the following: ///-------------------------------------------------------------------------------- /// <summary>This property gets the custom output pane.</summary> ///-------------------------------------------------------------------------------- private Guid _customPaneGuid = Guid.Empty; private IVsOutputWindowPane _customPane = null; private IVsOutputWindowPane customPane { get { if (_customPane == null) { IVsOutputWindow

Node fs.readstream() outputs <Buffer 3c 3f 78 6d 6c …> instead of readable data [duplicate]

主宰稳场 提交于 2020-01-13 10:34:08
问题 This question already has an answer here : Why does console.log(buffer) give me a hexadecimal list? (1 answer) Closed 6 years ago . I'm reading a large XML file (~1.5gb) in Node Js. I'm trying to stream it and do something with chunks of data, but I'm finding it difficult to understand the documentation. My current simple code is: var fs = require('fs'); var stream = fs.createReadStream('xml/bigxmlfile.xml'); stream.on('data', function(chunk){ console.log(chunk) }); The console gives a bunch

Append new data to an existing dataframe (RDS) in R

牧云@^-^@ 提交于 2020-01-13 09:33:07
问题 I have an Rscript that is reading in a constant stream of data in the form of a flat file. Another script picks up this flat file, does some parsing and processing, then saves the result as a data.frame in RDS format. It then sleeps, and repeats the process. saveRDS(tmp.df, file="H:/Documents/tweet.df.rds") #saving the data.frame On the second... nth iteration, I have the code only process the new lines added to the flat file since the previous iteration. However, in order to append the delta

using(IDisposable obj = new …) in C# to write code blocks in stream (e.g. XML)

亡梦爱人 提交于 2020-01-13 09:07:10
问题 I have started to use classes implementing IDisposable to write blocks in streams, with the using statement. This is helpful to keep a correct nesting and avoid missing or wrongly placed start/end parts. Basically, the constructor writes the start of a block (e.g. opening XML tag), Dispose() the end (e.g. closing XML tag). Example is the UsableXmlElement below (it's for large XMLs, so LINQ to XML or XmlDocument in memory are no options). However, these IDisposable do not implement the

Difference between ByteArrayOutputStream and BufferedOutputStream

↘锁芯ラ 提交于 2020-01-13 06:36:07
问题 Both ByteArrayOutputStream and BufferedOutputStream do buffering by placing data in an array in memory. So my questions are what are the differences between these two. When to use ByteArrayOutputStream and when to use BufferedOutputStream Can some one help me in above two questions as i am confused on this. 回答1: Just look at the javadoc: ByteArrayOutputStream: This class implements an output stream in which the data is written into a byte array. BufferedOutputStream: The class implements a