Browsing 7239 questions and answers with Jon Skeet

C#, Skipping Console.ReadLine(); Console.Read(); while in loop

If I run my code and insert correct value first time program works fine and does its job, but if I input wrong path and allow for loop to spin second time it skips...
Jon Skeet
people
quotationmark

The call isn't being skipped - the problem is that Console.Read() will only return after the user has hit return - although it will only consume the first character it reads. So suppose that (when prompted about skipping) the user... more 10/17/2014 12:38:03 PM

people

Base 64 decoding byte[] casted into a string

I got some encoded log information, casted into a string for transmitting purpose (the cast might be ugly but it works). I'm trying to cast it back to a byte[] in order to decode...
Jon Skeet
people
quotationmark

There are multiple problems here. In general, you need to use Base64.decode in order to reverse the result of Base64.encode: byte[] data = android.util.Base64.decode(to_decode, DEFAULT); In general, you should always ask yourself "How... more 10/17/2014 12:23:05 PM

people

Html5 time tag's datetime attribute day month order

What is the correct format for a html5 <time datetime="" /> attribute? Do days come before month or vice versa: <time datetime="yyyy-dd-mm"></time> or ...
Jon Skeet
people
quotationmark

It's yyyy-mm-dd, in order to comply with ISO-8601 and general sanity. From the W3C proposed recommendation: Note: While the formats described here are intended to be subsets of the corresponding ISO8601 formats, this specification... more 10/17/2014 11:52:58 AM

people

Understanding what is going on under the hood of Mockito framework

I have a problem understanding what is going on in the Mockito framework here. I have the following classes Model class public class KeyValueImpl{ private String key; ...
Jon Skeet
people
quotationmark

I suspect the problem is due to the order of the calls. Your last line is effectively: KeyValueImpl tmp = verify(keyValue); String value = expectationManager.getExpectedValue(); tmp.setValue(value); If Mockito is effectively using the... more 10/17/2014 11:02:11 AM

people

Posting minutiae byte array from applet to server

In Grails web application, I am trying to post minutiae (finger print) byte array from applet to server using rest API. This what i tried so for private String post(String...
Jon Skeet
people
quotationmark

This looks like a very bad idea to me: parameters.append(URLEncoder.encode(new String(regMin1),"UTF-8")); ... parameters.append(URLEncoder.encode(new String(regMin2),"UTF-8")); If regMin1 and regMin2 aren't actually UTF-8 text (and my... more 10/17/2014 10:18:50 AM

people

How to pre set a variable in a LINQ expression?

I'm creating an array of object based on data rows as shown below. While working, it bothers me a bit that I do as assignment to several fields by pulling the same value from a...
Jon Skeet
people
quotationmark

In a query expression, you can use let for this: return from DataRow row in table.Rows let preComputed = HeavyComputation(row["ID"]) select new Beep { // Use row and preComputed here }; To have the... more 10/17/2014 8:36:07 AM

people

Can the C# compiler insert constant values that auto increment on each usage at compile time?

Is there a way to have the C# compiler insert constant values that auto-increment at compile time? E.g. MyFunc(NEXT_CONSTANT); MyFunc(NEXT_CONSTANT); MyFunc(NEXT_CONSTANT); Would produce this code: MyFunc(1); MyFunc(2); MyFunc(3);
Jon Skeet
people
quotationmark

No, there's nothing in the language that does this. There are some grotty hacks that would allow you to keep track of the caller file/line/member, and auto-increment based on that (if you're using C# 5) - but it wouldn't really be the... more 10/17/2014 8:28:12 AM

people

Cannot convert type 'string' to 'byte[]'?

Hi I have to display student image on image box while selecting student ID from drop down list. The image is store in binary format in db.I want to display the image without...
Jon Skeet
people
quotationmark

Yes, the problem is here: byte[] barrImg = (byte[])(row["StudImage"].ToString()); You're calling ToString() on row["StudImage"]. That will result in a String. You're then casting that string to byte[] - but that doesn't work, because... more 10/17/2014 6:27:19 AM

people

How to convert String to date using Java in UNIX environment

I am trying to convert a String ("01-OCT-2014") into Date format. Below is my code for this. SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); Date d=...
Jon Skeet
people
quotationmark

I suspect the problem is simply that your Unix environment isn't running in an English locale - so when it tries to parse the month name, it's not recognizing "OCT" as a valid value. I would suggest using code like this: SimpleDateFormat... more 10/17/2014 6:17:35 AM

people

JodaTime LocalDate/LocalTime not Parsing with custom JSON Serializer classes

I have an object called ReportEvent which takes in a LocalTime as well as a LocalDate from the JodaTime API/framework. This ReportEvent is able to be written to JSON via google's...
Jon Skeet
people
quotationmark

The problem lies with the code you've got that's serializing the data. In your original question, you have this code when you're going to deserialize (retrieveGlobalDataFromStorage): final GsonBuilder builder = new GsonBuilder() ... more 10/16/2014 8:47:00 PM

people