Browsing 7239 questions and answers with Jon Skeet

Appending bytes to an existing file C#

I am working on a steganography software in C#, more precisely for video files. My approach is to append the extra information at the end of a video file. However, I must read the...
Jon Skeet
people
quotationmark

Sure, it's easy: using (var stream = File.Open(path, FileMode.Append)) { stream.Write(extraData); } No need to read the file first. I wouldn't class this as steganography though - that would involve making subtle changes to the... more 1/12/2015 2:44:14 PM

people

equals method for date comparison in the library java.util.Date

Is the method java.util.Date method .equals indifferent in what concerns the date format or not? I mean I've tried the date.before and date.after with different formats and they...
Jon Skeet
people
quotationmark

Is the method java.util.Date method .equals indifferent in what concerns the date format or not? A Date object doesn't have a format - it has no notion of where the information came from. It is just a number of milliseconds since the... more 1/12/2015 10:02:22 AM

people

Why there are JVM instructions `monitorenter/monitorexit` but no `wait/notifyAll` (they are native calls)?

When we write synchronized(some_object){} we can see two JVM instructions monitorenter/monitorexit issued as the byte code. When we write...
Jon Skeet
people
quotationmark

i would expect to see special JVM instructions like wait I wouldn't. That would be inconsistent, in my view - in the source code, you're just calling a method, so it makes sense that you're just calling a method in the bytecode as... more 1/12/2015 9:06:14 AM

people

Java reading wrong characters from file

I want to write a program that reads a text from a file character by character and counts how frequently each character occurs. I have the following code: import...
Jon Skeet
people
quotationmark

Look at your loop: while (in.hasNext()) { array[k] = in.next().charAt(k); k++; } This reads one token at a time, and takes the kth character from that token. So from "Good Morning" it retrieves character 0 of "Good" (G) and... more 1/11/2015 11:12:15 AM

people

Can I set a DataContext to a static class?

I've a static class which reads information from the application assembly. I've declared it static since the class needs no instance declaration and will only ever be read...
Jon Skeet
people
quotationmark

From the original version of the question: I've declared it static since I will only ever need a single application-wide accessible instance of the class. That's not what a static class is. You can never have any instance of a static... more 1/10/2015 7:50:48 PM

people

Why does 5.0 == 5L return me a true?

System.out.println(" answer is " + (5.0==5L)); This returns true! It should return a false value because two different types are being compared. Even though the double is...
Jon Skeet
people
quotationmark

The two operands are going through binary numeric promotion as per JLS section 5.6.2 in order to get to a single type for both operands. The rules are like this: If any operand is of a reference type, it is subjected to unboxing... more 1/10/2015 7:45:09 PM

people

Hiding/Overriding base class method with params in C#

I have an abstract class which has a method with params parameter as below. I want to override and hide this method with a method which takes certain number of parameters instead...
Jon Skeet
people
quotationmark

I want to override and hide this method with a method which takes certain number of parameters instead of params in inheriting class. You can't. That would break inheritance. Consider the following code: BaseClass bc = new... more 1/10/2015 3:05:52 PM

people

Parse large XML file into database. Use multiple threads?

I have a 5GB+ XML file that I want to parse into a MySQL database. I currently have a Ruby script that uses a Nokogiri SAX parser to insert every new book into the database, but...
Jon Skeet
people
quotationmark

This sounds like the perfect job for a producer/consumer queue. You only want one thread parsing the XML - but as it parses items (presumably converting them into some object type ready for insertion) it can put the converted objects onto... more 1/10/2015 12:48:28 PM

people

Create a NodaTime LocalDate representing "today"

What is the recommended way to create a LocalDate instance that represents "today". I was expecting there to be a static "Now" or "Today" property in the LocalDate class, but...
Jon Skeet
people
quotationmark

Matt's answer is spot on for Noda Time 1.x. In Noda Time 2.0, I'm introducing a ZonedClock, which is basically a combination of IClock and a DateTimeZone. As you're likely to want the current time in the same time zone multiple times, you... more 1/10/2015 12:43:10 PM

people

INFO: Server startup in 1054 ms java.sql.SQLException: ORA 00904: "USHA": invalid identifier

i am trying to execute a simple servlet program (in eclipse10.0 oracle10g, tomcat6.0 ), retrieving data from a table.but i am unable to do .checked with many forums n my code...
Jon Skeet
people
quotationmark

This is the problem: // BROKEN (will give query such as "select * from details where FIRSTNAME=Jon" rs=st.executeQuery("select *from details where FIRSTNAME="+name+""); I suspect you meant to add a single quote around the value of name,... more 1/10/2015 12:19:41 PM

people