Browsing 7239 questions and answers with Jon Skeet

System.OutOfMemoryException on server side for client files

I am getting data from client and saving it to the local drive on local host .I have checked it for a file of 221MB but a test for file of 1Gb gives the following exception: ...
Jon Skeet
people
quotationmark

You don't need to read the whole thing to memory before writing it to disc. Just copy straight from the network stream to a FileStream: byte[] length = new byte[4]; // TODO: Validate that bytesRead is 4 after this... it's unlikely but... more 12/26/2014 11:26:50 AM

people

variable scope inside of parametrized method java generics

why is it that inside this foreach loop, elem is not recognized as a Path, which it is, and I can only call Object methods on it? public class TypeOption<Path> implements...
Jon Skeet
people
quotationmark

It's because Path is a type parameter here - you've declared a generic type, with Path as the type parameter. I suspect you *wanted: public class TypeOption implements Option<Path> { At that point, Path refers to the existing type... more 12/25/2014 12:41:29 PM

people

Accessing a variable in a void from main

My Form1_Load: private void Form1_Load(object sender, EventArgs e) { Thread Usern = new Thread(new ThreadStart(Username)); Usern.Start(); } And my Username...
Jon Skeet
people
quotationmark

You should probably make user an instance variable instead of a local variable - in other words, declare it in your class: private string user; then in Username() (which should be renamed to DetectUserName or something similar) you... more 12/25/2014 9:15:35 AM

people

RuntimeMethodInfo equality: bug?

Lets start with: using System; public class Program { class A { public virtual void Do() { } } class B:A { } public static void Main() ...
Jon Skeet
people
quotationmark

I believe your assumption for the reasoning behind it - that two RuntimeMethodInfo instances can be compared by reference equality - is correct. Your assumption that it's broken isn't correct though. The two MethodInfo objects here are... more 12/25/2014 8:24:37 AM

people

Arrays.sort does not work in java

I am having a custom class called Company, and it has fields being latitude and longitude. I want to sort them based on distance from current location but it does not seem to...
Jon Skeet
people
quotationmark

Now we can see the string values for the latitude and longitude, I suspect I know the problem. Double.parseDouble will throw an exception for a string like this: 41,352979. My guess is that somewhere you're catching Exception and... more 12/24/2014 3:18:18 PM

people

Call async method properly on WP8.1

I'm sorry to ask such a basic/stupid question, but I'm lost. I've spent 3 days working on this stupid problem and can't find a solution. My problem is that the program freezes as...
Jon Skeet
people
quotationmark

This is the problem: listePaysT.Wait(); That will block until the task has completed... so you're blocking your UI thread. Worse, the async methods will need to return to the UI thread in order to continue, so you've got a... more 12/24/2014 2:52:33 PM

people

Can IntStream::noneMatch not evaluate the predicate on all the elements of the stream?

I read the Javadoc of IntStream::noneMatch.  It says :  Returns whether no elements of this stream match the provided predicate. May not evaluate the predicate on all...
Jon Skeet
people
quotationmark

so it should be able to return true without evaluating any elements No, in order to check that none of the elements match, it has to check everything. In other words, if it returns true then it will definitely have looked at... more 12/24/2014 12:11:51 PM

people

base 64 decode and write to doc file

I have a base64 encoded String . Which looks like this UEsDBBQABgAIAAAAIQDhD46/jQEAACkGAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAACAAAAAAAAAAAAAAAAAAAAAAAA...
Jon Skeet
people
quotationmark

The decoded data isn't plain text data - it's just binary data. So write it with a FileStream, not a FileWriter: // If your Base64 class doesn't have a decode method taking a string, // find a better one! byte[] decodedBytes =... more 12/24/2014 11:57:01 AM

people

Workaround the lack of 'new(parameters)' in generic in C#

I found two ways to workaround the lack of 'new(parameters)' in generics but I'm wondering if there's a better solution for that situation. I require a method in Earth that...
Jon Skeet
people
quotationmark

One option is to add another parameter: a Func<Dna, T>: private static T GetFruit<T>(Dna dna, Func<Dna, T> ctor) where T : Fruit { // I assume your real code does more here? return ctor(dna); } Then you can... more 12/24/2014 10:44:42 AM

people

IF IF Else doesn't work as I need and want

I need to know how I could handle my problem in a efficient and smart way: I want an error-handling for user's input; I have 2 fields CustomerID and Company: if...
Jon Skeet
people
quotationmark

Well, you could make it very explicit: if (customerIDExists) { ... } if (companyInvalid) { ... } if (!customerIDExists && !companyInvalid) { // Add user to DB } Or just use the fact that you haven't got an error... more 12/24/2014 10:18:39 AM

people