FAQ Database Discussion Community


Stream.CopyTo() does not copy data under a certain length

.net,vb.net,web-services,stream,file-transfer
I am currently working on a Windows Store Application in which I have to take a picture, save it locally and then when a sync is called send it to a service which will save the picture on the server. I am experiencing a problem in the copying of these...

How to check if Collection is not empty using java Stream

java,lambda,stream,java-8
I am new to Java 8. I am not able to understand what is wrong in the following piece of code. The idea is to sent Collection if its not empty . But if the collection is empty than sent HttpStatus.NOT_FOUND Entity response. @RequestMapping(value = "/find/pks", method = RequestMethod.GET, produces...

Access to mobile camera using HTML5 app

android,ios,html5,cordova,stream
I am developing HTML5 app that will be targeted for mobile platforms (mostly iOS, Android). Case is that user will open such page and use his mobile camera to take photo and then process it. I found that iOS browser isn't capable for HTML5 Stream API (http://caniuse.com/#feat=stream, http://mobilehtml5.org/). I thought,...

[http]How to identify end of stream when content-length is not specified?

node.js,http,stream,content-length,transfer-encoding
First let me show my code. http=require("http"); fs=require("fs"); var server=http.createServer(function(req,res){ var readStream=fs.createReadStream("1.jpg"); readStream.on("data",function(data){ res.write(data); }); readStream.on("end",function(data){ res.write("this string seems not to be sent","utf8"); res.end("end","utf8"); }); }); server.listen(3000); I created a readStream of picture 1.jpg and then sent data stream. After the "end" event was fired, I sent a string "this...

C / C++ - How to download byte by byte (like a file stream) from the web?

c++,c,url,download,stream
I'm building a simple download and file transfer manager in C and C++, with support for pause and resume operations. I looked for a way to download byte by byte from a given URL, but all I could find were references to external libraries like libcurl. I don't want external...

how to save a pdf to folder in root directory and return it to client

c#,kendo-ui,stream,asp.net-mvc-5.1
I am using kendo-ui chart export to pdf function. i am using a MVC controller to return it to the client, this works fine. I would like to also save the pdf into a folder as well. can i do both at the same time? [HttpPost] public ActionResult Save(string contentType,...

Stream an (SqlFile-)Stream using Nancy

memory,stream,nancy,sqlfilestream
I was wondering how to send an (in my case) SqlFileStream directly to the client through our Nancy-API without loading the stream in memory. So far I succeeded in passing the stream, but Nancy's StreamResponse copies the sourcestream (=SqlFileStream) to the outputstream which causes a massive memory increase. Where I...

Difference between generating a readable stream with fs and stream modules?

node.js,stream
Making a readable stream with the fs module: var http = require('http'); var fs = require('fs'); var server = http.createServer(function (req, res) { var stream = fs.createReadStream(__dirname + '/data.txt'); stream.pipe(res); }); server.listen(8000); and instantiating it through the stream module: var Readable = require('stream').Readable; var rs = new Readable; rs.push('file.txt'); rs.push('boop\n');...

Why does this stream function result in an error?

javascript,node.js,stream
I have written a function to be piped into that will log the supplied arguments to the console. function sconsole() { var stream = new Stream.Transform({objectMode: true}), foo = [].slice.call(arguments); stream._transform = function (data, encoding, callback) { console.log.apply(null, foo); callback(null, data); }; return stream; } Example use: stream .pipe(sconsole('foo')) .pipe(...);...

Perforce - switch to workspace from command line

stream,perforce,workspace
I am asking how to switch from client1 to client2 where client1 belongs to stream1 and client2 belongs to stream2. What I am looking for it to do the same as being in p4v and then right click on a workspace and selecting 'switch to workspace' Note, that if your...

Merging two List of objects in java 8

java,stream,java-8
Let's consider a java class Parent with Parent with 20 attributes (attrib1, attrib2 .. attrib20) and its corresponding getters and setters. List<Parent> list1 contains n Parent objects Parent objects. List<Parent> list2 contains n Parent objects Parent objects. Now I want to merge two list and avoid duplicate objects based on...

Should I use Stream.Flush before Stream.CopyTo?

c#,.net,stream,memorystream
I have MemoryStream that I'm filling up with some data using StreamWriter. At the end I want to dump it to different stream (not always file). Should I call Stream.Flush before using Steram.CopyTo method?...

createReadStream in Node.JS

javascript,node.js,file,stream,readfile
So I used fs.readFile() and it gives me "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory" since fs.readFile() loads the whole file into memory before calling the callback, should I use fs.createReadStream() instead? That's what I was doing previously with readFile: fs.readFile('myfile.json', function (err1, data) { if (err1)...

How can I achieve this using gulp?

javascript,node.js,stream,gulp
I am enumerating the subdirectories in a directory. For each sub directory I would like to apply a number of gulp activities like less compilation, and then create an output file specific to that subdirectory. I would like the gulp process to continue, as further transformation steps need to be...

Iterating multiple txt files in folder to read them in C#

c#,file,stream,iteration,streamreader
Problem: I need to iterate through multiple files in a folder and read them. They are .txt files. While reading I need to note what words occured in each file. For example: File 1 text: "John is my friend friend" -> words: John, is, my, friend File 2 text: "John...

Avoid NoSuchElementException with Stream

java,stream
I have the following Stream: Stream<T> stream = stream(); T result = stream.filter(t -> { double x = getX(t); double y = getY(t); return (x == tx && y == ty); }).findFirst().get(); return result; However, there is not always a result which gives me the following error: NoSuchElementException: No value...

Android: Closing output streams if data is constantly written to disk?

android,stream
I have a question regarding streams. I use them in order to write data to a file on my external sd card. Normally, a best practice is to close all streams when they are not needed anymore. But what if I'm constantly writing data to my storage device, like multiple...

Read a file one character at a time in node.js?

node.js,stream
Is there a way to read one symbol at a time in nodejs from file without storing the whole file in memory? I found an answer for lines I tried something like this but it doesn't help: stream = fs.createReadStream("walmart.dump", { encoding: 'utf8', fd: null, bufferSize: 1, }); stream.on('data', function(sym){...

Avoiding callback hell with multiple streams

node.js,stream,promise
How can I avoid using a recursion like structure when I got several streams to open and I have to get an absolute end event to finish the logic. var someArray = ['file1', 'file2', 'file3']; someArray.forEach(function( file ) { fs .createReadStream( file ) .pipe( /* do some stuff */ )...

Does closing a Stream close the BufferedReader source?

java,stream
From the docs: Streams have a BaseStream.close() method and implement AutoCloseable, but nearly all stream instances do not actually need to be closed after use. Generally, only streams whose source is an IO channel (such as those returned by Files.lines(Path, Charset)) will require closing. Most streams are backed by collections,...

HttpClient GetStreamAsync and http Status codes?

c#,stream,json.net,httpclient
I wish to use streams as recommended by the json.net performance tips documentation, however I'm unable to find how to get a hold of the http status codes without the typical awaiting the HttpResponse. Is there perhaps a way of getting the status code first without reading the data? So...

How can I create and use a stream of Pairs with Akka Streams for java?

java,stream,akka,akka-stream
Im trying to use the javadsl variant of Akka streams, and I seem to have hit a problem when I try to define a Flow which should take Pair elements. Say, for example, I have defined a Flow which accepts incoming Strings and Pairs it with a boolean stating wether...

Multiple streams over single project in Git?

git,version-control,stream,git-branch
I went through blog regarding GIT best practices model. As we are going to make GIT as our major head for SCM for the upcoming projects in our organization, I have some doubts, regarding them not able to find much over internet. Our project architecture is: We have only one...

Why does FileOutputStream corrupt my properties file?

java,file,io,stream
I have encountered a weird problem while coding a class to read/write settings. I'm using a properties file. In a prepare()-method, I want to load the in-/output streams to the file. When I only load the input stream everything works fine, but once I try to load the output stream...

java: Flush stream while creating zip file

java,stream
I have code for create zip file in servlet like this : ByteArrayOutputStream baos =null; baos = new ByteArrayOutputStream(); ZipOutputStream zos = new ZipOutputStream(baos); for(list of file){ bis = new BufferedInputStream(new FileInputStream(("somefile.extn")); other code for add entry in zip file bis.close(); } baos.flush(); zos.flush(); zos.close(); baos.close(); // Return bytes baos.toByteArray();...

Utilising the output of two previous gulp streams

javascript,stream,gulp
I would like to take the result of a CSS processing step getCss, and a JS processing step getJs, then use these two results to create a file named index.html, which is the result of inlining the processed CSS and processed JS into a template named index-template.html. Can someone help...

pre/post increment operator on OutputIterator

c++,stl,stream,iterator
I read in an article on OutputIterator that we only can dereference it as lvalue. My question is about operator++ which increments the iterator by one position. So, *it++ = t would be {*it = t; ++it; } https://www.sgi.com/tech/stl/OutputIterator.html Now, I am assuming that operator++ would be overloaded in such...

Parse text from Pdf, txt, or docx file from URL without downloading it in Java 8

java,parsing,pdf,stream,jsoup
I need to be able to parse the text contained in a file online with a given url, i.e. http://website.com/document.pdf. I am making a search engine which basically can tell me if the searched word is in some file online, and retrieve the file's URL, so I don't need to...

alternative to through2-map in node.js [related to learnyounode]

javascript,node.js,stream,request,response
Problem i am solving: Write an HTTP server that receives only POST requests and converts incoming POST body characters to upper-case and returns it to the client. Your server should listen on the port provided by the first argument to your program. My Solution var http = require('http'); var map...

Overhead of large length in PHP stream_get_line()

php,performance,sockets,stream
I'm testing out a PHP library which relies upon another streams based library. My experience is with sockets which is low level compared to streams so I'm a little unsure if streams is going to be flexible enough. Basically, using sockets, I would write a buffer loop which checked each...

Calculate a file hash and save the file

node.js,stream
Users upload files into my express app. I need to calc hash of the uploaded file and then write file to disk using calculated hash as a filename. I try to do it using the following code: function storeFileStream(file, next) { createFileHash(file, function(err, hash) { if (err) { return next(err);...

Convert byte array to generic value type?

c#,generics,types,stream,buffer
I have a Stream where I'd like to read data from (as value type segments) and move the position according to the size of the given type (declared as generics). My current approach: public byte ReadUInt8(Stream stream) { return (byte)stream.ReadByte(); } public ushort ReadUInt16(Stream stream) { return (ushort)((ReadUInt8() << 8)...

Lightweigth default StreamReader reading nothing

c#,stream
I am in the need of a default StreamReader reading nothing without throwing any exceptions. How can I efficiently construct such an object? Edit Specifically, if I read from the StreamReader object with ReadLine I would like to get null and no exception. ...

Poll multiple perforce streams with jenkins

jenkins,stream,continuous-integration,perforce
I have a Jenkins server monitoring a Perforce server. Perforce is using streams with mainline model. I am using Jenkins to monitor changes in Perforce and then setting off scripts depending on what is checked in where. This works great on the main stream but I would like to monitor...

Convert InputStream into Stream given a Charset

java,io,stream,java-8,java-stream
I want to convert an InputStream is into a Stream<String> stream given a Charset cs in such a way that stream consists of the lines of is. Furthermore a line of is should not be read immediately but only in case stream needs it.

InputStream, return to beggining

c#,validation,stream,asp.net-mvc-5,inputstream
I have a controller post method, which requires an uploaded file: View: @using (Html.BeginForm("UploadCSV", "TemporaryPerson", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForgeryToken() <div class="form-horizontal"> @Html.ValidationSummary(false, "", new { @class = "text-danger" }) <br /> <input type="file" name="personFile" /><input type="submit" value="Upload" /> </div> } and controller method: [HttpPost] public...

Why does the java DirectoryStream perform so slow?

java,performance,stream,nio
I've done some testing with Streams in special with DirectoryStreams of the nio-package. I simply try to get a list of all files in a directory sorted by last modified date and size. The JavaDoc of old File.listFiles() stated a Note to the method in Files: Note that the Files...

sharpziplib progressbar to extract targz

c#,stream,progress-bar,sharpziplib
I have an application which extracts targz files, I would like a ProgressBar to view the progress of extracting. But I just have this: public void ExtractTGZ(String gzArchiveName, String destFolder) { Stream inStream = File.OpenRead(gzArchiveName); Stream gzipStream = new GZipInputStream(inStream); TarArchive tarArchive = TarArchive.CreateInputTarArchive(gzipStream); tarArchive.ExtractContents(destFolder); tarArchive.Close(); gzipStream.Close(); inStream.Close(); } Have...

C++ stringstream value extraction

c++,stream,formatted-input
I am trying to extract values from myString1 using std::stringstream like shown below: // Example program #include <iostream> #include <string> #include <sstream> using namespace std; int main() { string myString1 = "+50years"; string myString2 = "+50years-4months+3weeks+5minutes"; stringstream ss (myString1); char mathOperator; int value; string timeUnit; ss >> mathOperator >> value...

How to reduce a stream into another stream in Java8?

java,stream
As an example, I want to create an infinite stream of Groups of tens like this: 0=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] 1=[10, 11, 12, 13, 14, 15, 16, 17, 18, 19] 2=[20, 21, 22, 23, 24, 25, 26, 27, 28, 29] ... I want to...

Sort multiple variable list with Java 8 stream

java,sorting,stream
I have a list of objects with multiple variables. I want to sort this list according to a run-time decided sequence. I cam up with the following code which looks not efficient at all. For example, what happens if the variable is not 3 but 10 or 30? Can anyone...

Passing subsequence of a stream without copying its content into a new instance

c#,stream,filestream
Let's assume I have following method: void Upload(Stream stream) { // uploads the content of the specified stream somewhere } And let's further assume I got some binary file f, which contains some data I'd like to upload with the method above. But: It's not the whole file I want...

JQ: Enumerate Object Stream

object,stream,enumerate,jq
I've got a pipe full of objects and I am trying to add a accumulating count string to each object in a stream with jq to get the following output {"count":"Num_000"} {"count":"Num_001"} {"count":"Num_002"} {"count":"Num_003"} {"count":"Num_004"} {"count":"Num_005"} {"count":"Num_006"} {"count":"Num_007"} {"count":"Num_008"} {"count":"Num_009"} Something like the following but I'm sure I don't need...

How to only read a few lines from a remote file?

ruby,download,ftp,stream
Before downloading file, I need to set up a way it (the .csv typically, but not always) will be parsed. I don't want to download the whole file especially if the "headers" do not match what is expected. Is there a way to only download up until a certain number...

Pipe continuous stream to another command

awk,stream,pipe,tail
I wrote a program to analyze the log files in real time. I need to feed it with the IPs. It works fine with the command: cat /var/log/apache2/access.log | awk '{print $1}' | ./my_program Also, I can get the IPs in real time with the command: tail -f /var/log/apache2/access.log | awk '{print...

How to asynchronously read/write in C++?

c++,multithreading,asynchronous,stream
How do you copy one stream to another using dedicated read/write threads in C++? Let's say I have these methods (not real, but to illustrate the point) to read/write data from. These read/write functions could represent anything (network/file/USB/serial/etc). // returns the number of bytes read void read(char* buffer, int bufferSize,...

Streams in JavaScript

javascript,node.js,stream
I am using gulp and would like to create a function that can be piped into that passes on the input to the output and writes a single line to the console. For example: this.src('/foo') .pipe(myFunction) .pipe(...) Can someone help me understand what myFunction needs to look like? The following...

how to implement a Stream for java

java,stream
I wan't to implement a Stream<T> I searched for some good tutorials but all I find is how to use streams. Not how to provide a Stream. I figured if you use implements Stream<T> you have to implement a ton of methods: Can this be avoided? To be more concrete,...

Are Stream.ReadAsync and Stream.WriteAsync supposed to alter the cursor position synchronously before returning or after the operation completes?

c#,stream,async-await,filestream,c#-5.0
I've been attempting to implement a Stream that supports ReadAsync and WriteAsync, and given the spareseness of the documentation, I'm struggling to understand how to do so properly. Specifically, with respect to the stream's cursor position. A similar question was asked here and here regarding the old BeginRead function. The...

Downloading file from Java servlet gives null

java,file,servlets,stream
I am trying to create a method that allows users to download a file on the file system via a Servlet. Right now, the correct filename shows on the download and a file is downloaded but the contents of the file are always null. I've also tried to get the...

How to remove a collect into a new stream from the middle of a java 8 stream?

stream,java-8
I'm working on a Java 8 stream. And I need group by 2 keys in a map. And then put these keys with their value into a new function. Is there a way to skip the collector and reading it out again? graphs.stream() .map(AbstractBaseGraph::edgeSet) .flatMap(Collection::stream) .collect(Collectors.groupingBy( graph::getEdgeSource, Collectors.groupingBy( graph::getEdgeTarget, Collectors.counting()...

How to implement a ByteCountingStreamReader?

python,stream
How to implement a ByteCountingStreamReader? The ByteCountingStreamReader should wrap a file descriptor stream and count the bytes it passed. A bit like codecs.StreamReader, but the content should not be changed, just counted. Use case: Solve http://bugs.python.org/issue24259 The tarfile library does not compare the file size of the TarInfo with the...

Is Node.js stream Duplex only there for subclassing?

node.js,stream
I have a need in my code to simultaneously push out live streaming data to multiple clients that comes from a single source, but the clients may or may not be all connected to receive the live stream data. So I need to be able to simultaneously write to a...

How do I only send the differences between two images over the network? [duplicate]

c#,image,sockets,stream,comparison
This question is an exact duplicate of: Sequential PrintScreens Comparison, Generate a difference image? 1 answer I am making a program which sends images (actually screenshots) over a tcp connection by serializing the byte array (of course after a conversion from image to byte array) to a network stream....

Find and append to file without loading it in memory?

c#,.net,file,io,stream
Im writing a simple XML file for logging that looks like this : <root> <objects> </objects> </root> The file is created the first time like this using (xmlWriter = new XmlTextWriter(filePathAndName, System.Text.Encoding.UTF8)) { xmlWriter.Formatting = Formatting.Indented; xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("root"); xmlWriter.WriteStartElement("objects"); xmlWriter.WriteEndElement(); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); xmlWriter.Close(); } Now I need to place...

How to get each track of a playlist with the Soundcloud API?

javascript,api,stream,soundcloud
I am working with the Soundcloud API to create a custom playlist (another look than the original Soundcloud player). See image below. I am develop a website for an artist. With the API of Soundcloud I want to import his music from Soundcloud to the website. There are different tabs...

Create an empty stream from a string on which Stream.Read() waits when no data

c#,string,stream,tcpclient
I am trying to replace the stream i get from TcpClient.GetStream() by a stream I create from a string. I am using the following method to create said Stream: public Stream GenerateStreamFromString(string s) { MemoryStream stream = new MemoryStream(); StreamWriter writer = new StreamWriter(stream); writer.Write(s); writer.Flush(); stream.Position = 0; return...

Flush cout manually only

c++,stream,cout,flush
As far as I know streaming std::endl into std::cout will flush it. I get that that behavior makes sense for most applications. My problem is that I have some output that uses multiple std::endl's and therefore flushes the output. This is really bad for the performance of my program and...

Java 7 - Stream data through class hierarchy

java,performance,io,stream
I am trying to write some sort of class hierarchy, more specifically, an execution hierarchy. Data should be passed down the hierarchy through each element whilst being modified during the process. Concurrency is not an issue, although it is part of a multithreaded program. To clarify: I do not want...

How to return zip from bytearray on Servlet [duplicate]

java,servlets,stream
This question already has an answer here: How to create a zip file in Java 5 answers working again with Java EE. In example On servlet I have byte[] fileContent ---->(file.txt) I try to add it to zip file set servlet as response.setContentType("Content-type: text/zip"); response.setHeader("Content-Disposition", "attachment; filename=mytest.zip"); // List...

How to find condition that start char in UTF-8 file is read, using FileStream and StreamReader?

c#-4.0,utf-8,io,stream
In C# .NET 4.0 (really 4.5.2), my code reads a UTF-8 file. FileStream fstream = new FileStream(path, FileMode.Open); BufferedStream stream = new BufferedStream(fstream); using (StreamReader reader = new StreamReader(stream, new UTF8Encoding())) { int i; while((i = reader.Read()) > -1) { //a guess at a condition that is true I.F.F. reader...

Can't find embedded resource using GetManifestResourceStream

c#,stream,embedded-resource,system.drawing
I'm currently working on a Card DLL in which I would need the image files for each card as an embedded resource, the current project looks like this: Note: The card images (.png) are in the Resources folder. The code I've been trying & is pretty much the only code...

How do I customize and use Phirehose functions?

php,twitter,oauth,stream,phirehose
I'm trying to put in a check for Phirehose to stop running after 10 seconds or 100 tweets...basically, I want to be able to stop the script. I was told I could customize the statusUpdate() function or the heartBeat() function, but I'm uncertain how to do that. Right now, I'm...

How to get only specific strings or records from Twitter

r,api,twitter,stream
names(st)<-c("id_str", "created_at", "text", "location") parseTweets(filterStream(file.name= "", track=c("climate change"), timeout=10, oauth=twitCred))$st # [1] 6113 214 3649 1444 4483 270 8022 41946 494038 8925 3454 5249 20517 14790 14276 15316 583259 4254 3962 6635 52878 3669 2230 6186 9348 583267 #[27] 46894 17360 18038 3764 I do not want to see the...

.Net System.IO.Stream async/nonblocking

c#,.net,asynchronous,stream
I'm wanting to wrap an external resource and convert it into a stream in my application (to be then consumed by PushStreamContent in a webapi controller). The documentation for Streams in C# doesn't really infer how I can create one that uses the async methodology. Eg trying to inherit from...

Joining two files in C#, split options

c#,file,split,stream,streamreader
I am currently trying to work on files, joining multiple of them and having problem because the last work from file 1 is linked with first word from file 2. For example: File 1:John has got new haircut File 2: Mike has got new haircut and it prints me "haircutMike"....

Files.readAllBytes vs Files.lines getting MalformedInputException

java,file-io,stream
I would have thought the following to approaches to read a file should behave equally. But they don't. The second approach is throwing a MalformedInputException. public static void main(String[] args) { try { String content = new String(Files.readAllBytes(Paths.get("_template.txt"))); System.out.println(content); } catch (IOException e) { e.printStackTrace(); } try(Stream<String> lines = Files.lines(Paths.get("_template.txt")))...

Memorative art of Streams

stream,terminology
I'm trying to understand Streams. How comparable is a stream (computer science) with a stream (water). This is how I picture them in my mind: Now, I was wondering whether this thought is correct. If it's not a correct way, why isn't this a correct way?...

Java 8 Stream with batch processing

java,stream,java-8,batch-processing
I have a large file that contains a list of items. I would like to create a batch of items, make an HTTP request with this batch (all of the items are needed as parameters in the HTTP request). I can do it very easily with a for loop, but...

How to write unitTest for methods using a stream as a parameter

c#,unit-testing,stream
I have class ImportProvider , and I want write unit test for Import method. But this should be unit test, so I don't want to read from file to stream. Any idea? public class ImportProvider : IImportProvider { public bool Import(Stream stream) { //Do import return isImported; } } public...

What is the proper way to remove a stream from stdout so that another stream may be added?

asynchronous,stream,dart,stdout
I am starting a process in Dart that attaches its stdout stream to stdout so that the results can be printed to the terminal like so: Process.start(executable, ['list','of','args']).then((proc) { stdout.addStream(proc.stdout); stderr.addStream(proc.stderr); return proc.exitCode; }); However, once this completes I would like to start a new process and begin this again...

How to calculate differences in a list of integers using lambda expressions

java,lambda,stream
Lets say I have the following array: {1,2,3,4,6,7,8} which is put in a Stream<Integer> s = Stream.of(1,2,3,4,6,7,8); How can I use in Java lambda expressions and Stream functions to calculate the difference between each element and the next (in this case {1,1,1,2,1,1})? This is not really a reduce operation as...

getting two consicutive value from file in java

java,file,csv,stream,filereader
I am working with a csv file, and I want to extract two values in specific positions from each and every row. The csv input file looks like this: a, b, c, d 12,32,45,76 23,45,77,56 32,34,49,28 73,92,26,68 73,36,77,26 For example I want the two consecutive values from the 3rd position...

Stream Data to Website from Android device

android,node.js,data,stream
For a project I would like to stream the sensor data of an Acceleromter (from an android phone) to a website. Basically I have written the application that reads the data and stores it on the phone and converts it to a string. I just want to plot the x,...

Java list: get amount of Pairs with pairwise different Keys using lambda expressions

list,lambda,stream,hashmap
I have a list of key-value-pairs and I want to filter a list where every key parameter only occurs once. So that a list of e.g. {Pair(1,2), Pair(1,4), Pair(2,2)} becomes {Pair(1,2), Pair(2,2)}. It doesn't matter which Pair gets filtered out as I only need the size (maybe there's a different...

How to display multiple leading zeros for floating point values in C++? [duplicate]

c++,stream,printf,double,stringstream
This question already has an answer here: How can I pad an int with leading zeros when using cout << operator? 6 answers In a C++ program, I want to display a column of floating point values so that the sign, digits, and decimal point all line up. Multiple...

Write only stream - get written bytes count with DataContractSerializer

c#,stream,datacontractserializer
Consider I have the following snippet: public void Store(Stream s, object t) { var serializer = new DataContractSerializer(target.GetType(), new DataContractSerializerSettings { PreserveObjectReferences = true }); serializer.WriteObject(s, target); } where s is write-only and doesn't support seeking. Is there any way to get bytes count that was written to stream by...

Node.js: How to append files to a (archiverjs) zip from url

javascript,node.js,stream,zip
I have an object containing an array of slides. Every slide can have a media parameter containing the url to an image or video file or the link to a youtube or vimeo video. My goal is to have the slides viewer zipped and inside the zip I also must...

Get line-numbers in which a certain word/text occurs

java,stream
What I have: I have a file which is read line by line. These lines are not counted within the file. What I want to do: I want to count each line within ONE stream and return only the numbers in which a certain text occurs. What I have so...

NodeJS - Seeing data events from readable stream without corresponding pause from writable stream

node.js,amazon-s3,stream
We are seeing some extremely high memory usage with some of our streams in production. The files are stored in S3 and we open a readable stream on the S3 object, and then we pipe that data to a file on our local filesystem (on our EC2 instance). Some of...

Most efficient way to read the number of XML nodes directly under the root element

c#,xml,performance,stream
I need to count the number of nodes that are places directly under the root element in an XML stream. I don't care about any of the subnodes. For example, for the following XML it should return 4: <?xml version="1.0" encoding="utf-8"?> <root> <node1> <subnode1_1> <subnode_1_1_1> <subnode_1_1_1_1>…</subnode_1_1_1_1> </subnode_1_1_1> <subnode_1_1_2>…</subnode_1_1_2> </subnode1_1> </node1>...

Read and write int pairs from file

c++,file,input,stream,output
I'm trying to read and write a sequence of int pairs from a file. The file would look something like this: 0 6 12 24 48 33 23 24 80 79 My goal is to read each pair into a struct: struct foo { int a; int b; } And...

fstream using formatted data

c++,stream,fstream
i am new to this site , and this my first question ! i have a question about fstream function . fstream f("new.dat",ios::out|ios::in); fstream is for both input and output , so when we use it like this , and there is a new.dat file before it will output and...

Are streams in ocaml really used?

stream,ocaml,ocaml-lwt
Looking at different ocaml projects, I don't see the built-in Streams in the language ever used. Even in the recent Real World Ocaml book, Streams are not mentioned at all, which is odd. What's the reason for that? Is it because Lwt or Core superseed them?...

Adding a stream to an ISO as a File

c#,stream,filesystems,imapi
I am using the IMAPI2FS Image Mastering API in Windows, and I'm trying to figure out how to add a stream as a file to the file system image before I generate the ISO. var fsi = new MsftFileSystemImage(); fsi.ChooseImageDefaultsForMediaType(IMAPI_MEDIA_PHYSICAL_TYPE.IMAPI_MEDIA_TYPE_DISK); fsi.FileSystemsToCreate = FsiFileSystems.FsiFileSystemISO9660 | FsiFileSystems.FsiFileSystemJoliet; using (var stream = new...

Data loss when writing bytes to a file

java,string,file,stream,compression
I'm working on a string compressor for a school assignment, There's one bug that I can't seem to work out. The compressed data is being written a file using a FileWriter, represented by a byte array. The compression algorithm returns an input stream so the data flows as such: piped...

Java - Start Upload after Download

java,stream
My program just can do 1 transaction which is Downloading or Uploading but can't Downloading then Uploading The Server: ServerSocket serverSocket = new ServerSocket(4444); Socket socket = serverSocket.accept(); /* GET */ InputStream is = socket.getInputStream(); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("E:\\23c-dl.mkv")); int count; byte[] bytes = new byte[8192]; while ((count...

Transforming JSON in a node stream with a map or template

javascript,json,node.js,stream,request
I'm relatively new to Javascript and Node and I like to learn by doing, but my lack of awareness of Javascript design patterns makes me wary of trying to reinvent the wheel, I'd like to know from the community if what I want to do is already present in some...

Most efficient way to transmit file over TCP

c#,serialization,tcp,stream,base64
I'm currently transmitting files by Gzipping them and then converting to a base64 string, it's working well enough however I'd like to make it more efficient if possible as I'm sure this is not the best way to do it due to the 33% size increase due to Base64. The...

Java StreamTokenizer splits Email adress at @ sign

java,email,stream,tokenize
I am trying to parse a document containing email adresses, but the StreamTokenizer splits the E-mail adress into two seperate parts. I already set the @ sign as an ordinaryChar and space as the only whitespace: StreamTokenizer tokeziner = new StreamTokenizer(freader); tokeziner.ordinaryChar('@'); tokeziner.whitespaceChars(' ', ' '); Still, all E-mail adresses...

how to write the output of iostream to buffer, python3

python,string,io,stream,wrapper
I have a program that reads data from cli sys.argv[] and then writes it to a file. I would like to also display the output to the buffer. The manual says to use getvalue(), all I get are errors. Python3 manual import io import sys label = sys.argv[1] domain =...

Why do we need to avoid mutation while coding? What is mutation?

java,lambda,stream,mutation
Why the second part of the code (with the stream) is a better solution compared to first? First : public static void main(String [] args) { List<Integer> values = Arrays.asList(1,2,3,4,5,6); int total = 0; for(int e : values) { total += e * 2; } Secound : System.out.println(total); System.out.println( values.stream()...

error write large file got request entity too large

javascript,node.js,post,stream,fs
I use the following code to send from the browser body(via postman ) file content which is large file. before for small file I use the following which work perfect fs.writeFile(filePath, req.body, 'utf8', function (err) { ... now I use the following app.post('/bb',function(req,res){ var filePath = 'C://test.txt'; var writeStream =...

Why is the file being overwritten?

vb.net,stream,file-writing,wildfire-api
I'm designing a new server application, which includes a subroutine that parses the input into the console window, for example LogAlways("--- CPU detection ---") will be written as: [net 21:8:38.939] --- CPU detection --- This is the subroutine: Public Sub LogAlways(ByVal input As String) Dim dm As String = "[net...

AppDomain.CurrentDomain.BaseDirectory path issue when running MVC project

c#,file,stream
This code creates a log file in App_Data folder. If file doesn't exist it's created. It works when the MVC page is published on my IIS. var filename = AppDomain.CurrentDomain.BaseDirectory + "App_Data//" + label + DateTime.Now.ToString() + ".txt"; var sw = new System.IO.StreamWriter(filename, true); However when i run the project...

One symbol at time stream with node

node.js,stream
I'm trying implement a stream which returns one symbol from file on each 'data' event. I finished with code bellow: var util = require('util'), fs = require('fs'), Readable = require('stream').Readable; var util = require('util'); var Readable = require('stream').Readable; var SymbolReadStream = function(filename, options) { Readable.call(this); this._readable = fs.createReadStream(filename, options).pause(); self...

c# send images over socket as fast as posibble

c#,image,sockets,stream
hello guys im trying to send as fast as possible images over socket tryed to compress... comapre the images... it's still working pretty slow... btw i tried to save the image before and after the compression and size was the same.... 1 or 2 kb les... have a look in...

In Java how to read the latest string of constantly generated stream fast?

java,stream,real-time
In Java I have a process constantly generating output. Of course it's placed into some buffer of the out stream (FiFo) until it's processed. But what I need is sometimes read the latest, actual string of the stream as if it was LiFo. The problem is when I need it,...

Issues parsing a 1GB json file using JSON.NET

json,parsing,stream,json.net,large-object-heap
I have gotten an application where the input has been scaled up from 50K location records to 1.1 Million location records. This has caused serious issues as the entire file was previously de-serialized into a single object. The size of the object is ~1GB for a production like file with...

Reading an external txt file on main.class

java,file,stream,external
I have a litlle question that, I have a blank main class, and the thing is that I want to know how can I read a external .txt file located on the package of main.java (testes package has main.java and LerDaqui.txt) and I want to know how can I read...