Browsing 7239 questions and answers with Jon Skeet

Web Client timeout while downloading photos from external link

I am trying to download 10 photos from an external link e.g http://images.net/images/20159178574IMG_0843.jpg I am reading a text file on my drive and putting it on a list here is...
Jon Skeet
people
quotationmark

It looks like your problem is in the checkurl method, which doesn't dispose of the WebResponse that it gets - that means the connection pool associated with that host has effectively "lost" that connection until the WebResponse gets... more 9/22/2015 6:14:45 AM

people

Java Convert Big Endian to Little Endian

I have the following hex string: 00000000000008a3a41b85b8b29ad444def299fee21793cd8b9e567eab02cd81 but I want it to look like this: ...
Jon Skeet
people
quotationmark

You need to swap each pair of characters, as you're reversing the order of the bytes, not the nybbles. So something like: public static String reverseHex(String originalHex) { // TODO: Validation that the length is even int... more 9/21/2015 10:57:46 AM

people

How to get Enum when it's string representation and type are known at Runtime?

Suppose I have an Enum as: com.mypackage.enums public enum Days { MONDAY, TUESDAY, WEDNESDAY } Now somewhere I know that I need to get enum MONDAY from a runtime...
Jon Skeet
people
quotationmark

You can use Enum.valueOf(Class, String): import java.util.*; enum Day { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY } public class Test { public static void main(String[] args) throws Exception { ... more 9/21/2015 5:56:25 AM

people

How to get the remaining time from 24 hours in C#

This is currentTime(EST) "2015-09-20 04:25:49.090". I need the below calculation. Remaining time of "2015-09-20 04:25:49.090" this day (Ex : remaining time of this day is : 19...
Jon Skeet
people
quotationmark

Sure - you do exactly as you've described, using TimeSpan. You can get the time of day from a DateTime using the TimeOfDay property, and then just subtract that from 24 hours: // You could use TimeSpan.FromDays(1) as well var remaining =... more 9/20/2015 8:32:04 AM

people

I'm not understanding the usage of C# get; set; seems to be different from Java

I know there are a few questions on stack overflow on this already but I haven't found any that answer my specific question. I came from a java development background and never...
Jon Skeet
people
quotationmark

When you write this (I'm using different class and property names for clarity): public class Test { public string Name { get; set; } } that's asking the compiler to create a private field with a public property. It's equivalent... more 9/19/2015 3:24:18 PM

people

C# multidimensional immutable array

I need to create a field for simple game. In first version the field was like Point[,] - two dimensional array. Now i need use System.Collections.Immutable (it's important...
Jon Skeet
people
quotationmark

There isn't the equivalent of a rectangular array as far as I'm aware, but you could: Have an ImmutableList<ImmutableList<Point>> Wrap a single ImmutableList<Point> in your own class to provide access across two... more 9/19/2015 2:09:09 PM

people

What did I miss to send a http part post request

I am trying to send an image using http multipart request (later I will add another image) I did this: HttpClient client = HttpClientBuilder.create().build(); HttpPost...
Jon Skeet
people
quotationmark

Look at when you're calling execute - that's before you build the request properly! Just reorder your code so that you fully build the request, then you post it to get a response, then you use the response. (I'd also be personally... more 9/18/2015 2:01:13 PM

people

String.Format is not working on dates

I am executing a sql query and storing it in a dataset, from there i am sending an email, everything works as expected, except for this time attached to the date 12:00:00 Am, it...
Jon Skeet
people
quotationmark

This is the problem: string Date = ds1.Tables[0].Rows[0]["Date"].ToString(); Your Date variable is already a string, so trying to format that as if it's a DateTime isn't going to work. You want something like: DateTime Date =... more 9/17/2015 2:45:02 PM

people

Is daemon thread lighter than normal thread?

I'm new in Java world so at the moment I'm learning about Threads. I've read that daemon thread is described as background task, so I thought that it means it's lighter than the...
Jon Skeet
people
quotationmark

No, the only difference between daemon threads and non-daemon threads in Java is that a non-daemon thread prevents the JVM from terminating, whereas a daemon one doesn't: once all non-daemon threads have completed, the JVM will exit. more 9/17/2015 1:30:28 PM

people

Does Action<T> prevent enclosing class instance to be GCed when all other references to class instance are removed?

I wonder whether Action<T> prevents an enclosing class instance to be garbage collected when all other references to such class instance are removed during runtime? public...
Jon Skeet
people
quotationmark

I wonder whether Action<T> prevents an enclosing class instance to be garbage collected when all other references to such class instance are removed during runtime? No. If the delegate instance were still referenced elsewhere,... more 9/17/2015 9:48:54 AM

people