With JSR 203 (to be implemented in Java SE 7), we get a new set of future legacy methods. This is Sun's third major attempt in 13 years to get I/O right. And from what I've seen, it doesn't look good. (Examples here.) My main question at this point is where they got that much lipstick.
The main innovation is the new Path object, which seems to be a very slightly more abstract version of File. (This is progress?) You would think any new I/O library these days would make heavy use of URIs, URLs, and Schemes (file:, http:, etc.) and lessons learned in the realization of concepts like REST, AJAX, and dependency injection. No such luck. Instead we have exotic new calls like
FileSystem.getRootDirectories()and DirectoryEntry.newSeekableByteChannel(). It's like we've learned nothing at all in the last 20 years.When I want to do I/O, I want to be able to do something like
dataSrc = new DataGetter( );
dataSrc.setPref( DataGetter.EIGHTBITBYTES );
dataSrc.setPref( DataGetter.SLURPALL );
data = dataSrc.getData( uri );
and be done with it. (And by the way, let me pass a string for the URI, if I want to. Don't make me create a special object.)
I don't want to have to know about newlines, buffering, or file-system obscurata, unless those things are terribly important to me, in which case I want to be able to inject dependencies at will. But don't make me instantiate totally different object types for buffered vs. non-buffered streams, and all the rest. Don't give me a million flavors of special objects. Just let me pass hints into the DataGetter, and let the DataGetter magically grok what I'm trying to do (by making educated guesses, if need be). If I want a special kind of buffering, filtering, encoding, error-handling, etc., let me craft the right cruftball of flags and constants, and I'll pass them to the DataGetter. Otherwise, there should be reasonable defaults for every situation.
I would like a file I/O library that is abstract enough to let me read one bit at a time, if I want; or 6 bits at a time; or 1024 bits, etc. To me, bits are bits. I should be able to hand parse them if I want, in the exact quantities that I want. If I'm doing some special type of data compression and I need to write 13 bits to output, then 3 bits, then 12, then 10, and so on, I should be able to do that with ease and elegance. I shouldn't have to stand on my head or instantiate exotic objects for reading, buffering, filtering, or anything else.
I could write a long series of articles on what's wrong with Java I/O. But I don't look forward to revising that article every few years as each "new" I/O package comes out. Like GUI libraries and 2D graphics, this is something Sun's probably never going to get right. It's an area that begs for intervention by fresh talent, young programmers who are self-taught (not infected by orthodoxies acquired in college courses) and have no understanding at all of legacy file systems, kids whose idea of I/O is HTTP GET. Until people with "beginner's mind" get involved, there's no hope of making Java I/O right.
Well said!
ReplyDeleteI am a Java beginner (but in software development since more than twenty years) - but from what I have seen so far in the standard libraries of Java 6: Full ACK to your post! And I would even go further:
ReplyDeleteIn many cases file content can be a small text template only for example (for composing an email for instance) and something like public static String readContent(String fileName) would be nice.
In Java 6 I couldn't either find a copyFile method (maybe only overlooked so far?) but at least 5 ways how it could be done (maybe that's the reason why there is no implementation available "by default"). So what about some default methods like copySmallFile (read the whole content at once and write it to destination) and copyLargeFile (uses limited buffers)?
Why do I have to always write such basic routines again and again in every new language I am learning?
Instead of the basic stuff that helps getting started we get frameworks and other abstract stuff...
I/O means different things to different people as there are many layers in the stack. The abstraction in the Java Platform that represents a connection to a resource identified by a URL is URLConnection. For example, url.openStream opens a connection to the resource so that you can read its contents. The abstraction is okay for many cases and may provide a starting point for your declarative API. You are right that the platform does lack utility methods to save the developer from having to deal with streams of bytes, buffering, line separators, etc. We need to address this so that the common cases are easy to use and save the developer from having to remember many of these details. In any case, high level/abstract APIs are fine for many cases but they can be awkward when you wan to do something very specific. (JNDI is good example where it can be awkward when you need to do something very specific with LDAP or DNS for example). New I/O brings APIs to address specific problems or areas. The first installation of New I/O focused on charsets, buffers, and support for multiplexed/non-blocking I/O needed when building highly scalable server applications. The second phase of New I/O must address the needs of applications and tools that want to access the file system directly. File I/O has mostly been ignored since JDK1.0. URIs can be used to locate files (also file systems when using the provider interface).
ReplyDeleteYou can still use http://commons.apache.org/io/. It provides a lot of utilities you're looking for.
ReplyDeleteVery much useful article. Kindly keep blogging
ReplyDeleteJava Training in Chennai
Java Online Training India
Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
ReplyDeleteAdvanced AWS Training in Bangalore | Best Amazon Web Services Training Institute in Bangalore
Advanced AWS Training Institute in Pune | Best Amazon Web Services Training Institute in Pune
Advanced AWS Online Training Institute in india | Best Online AWS Certification Course in india
AWS training in bangalore | Best aws training in bangalore
Nice tutorial. Thanks for sharing the valuable information. it’s really helpful. Who want to learn this blog most helpful. Keep sharing on updated tutorials…
ReplyDeleteBest Devops online Training
Online DevOps Certification Course - Gangboard
Great content thanks for sharing this informative blog which provided me technical information keep posting.
ReplyDeletepython Course in Pune
python Course institute in Chennai
python Training institute in Bangalore
Great Article
ReplyDeleteAWS Training in Bangalore
Best AWS Training Institute in Bangalore
Attend The Python training in bangalore From ExcelR. Practical Python training in bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Python training in bangalore.
ReplyDeletepython training in bangalore
Attend The Best Python Training in Bangalore From ExcelR. Practical Python Training in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Best Python Training in Bangalore.
ReplyDeleteI like viewing web sites which comprehend the price of delivering the excellent useful resource Python classes in pune free of charge. I truly adored reading your posting. Thank you!
ReplyDeleteI am looking for and I love to post a comment Python classes in punethat "The content of your post is awesome" Great work!
ReplyDeleteData for a Data Scientist is what Oxygen is to Human Beings. business analytics course with placement this is also a profession where statistical adroit works on data – incepting from Data Collection to Data Cleansing to Data Mining to Statistical Analysis and right through Forecasting, Predictive Modeling and finally Data Optimization.
ReplyDeleteNice Post...I have learn some new information.thanks for sharing.
ReplyDeleteData Science Courses in Bangalore | Data Science training | Best Data Science institute in Bangalore
Nice Post
ReplyDeleteFor Data Science training in Bangalore, Visit:
Data Science training in Bangalore
Attend The Data Analytics Course From ExcelR. Practical Data Analytics Course Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Course.
ReplyDeleteExcelR Data Analytics Course
Attend The Data Analytics Courses Online From ExcelR. Practical Data Analytics Courses Online Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Data Analytics Courses Online.
ReplyDeleteExcelR Data Analytics Courses Online
This post is really nice and informative for me. The explanation given is really comprehensive and informative. Keep posting!!
ReplyDeleteMachine Learning Course Bangalore
It is better to engaged ourselves in activities we like. I liked the post. Thanks for sharing. Machine Learning Course Bangalore
ReplyDeleteI’m impressed, I must say. Rarely do I come across a blog that’s both equally educative and entertaining, and without a doubt, you have hit the nail on the head. The problem is something which too few folks are speaking intelligently about. Now i'm very happy that I came across this during my hunt for something concerning this. onsite mobile repair bangalore Oh my goodness! Awesome article dude! Many thanks, However I am going through troubles with your RSS. I don’t understand why I can't subscribe to it. Is there anybody else having identical RSS problems? Anybody who knows the solution can you kindly respond? Thanx!! asus display repair bangalore An outstanding share! I have just forwarded this onto a coworker who has been conducting a little research on this. And he in fact ordered me breakfast because I stumbled upon it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanx for spending some time to discuss this matter here on your web site. huawei display repair bangalore
ReplyDeletePretty! This has been a really wonderful post. Many thanks for providing these details. online laptop repair center bangalore Greetings! Very useful advice in this particular article! It is the little changes that make the most significant changes. Thanks for sharing! dell repair center bangalore
ReplyDeleteYour style is so unique compared to other folks I have read stuff from. I appreciate you for posting when you've got the opportunity, Guess I will just book mark this blog. macbook repair center bangalore I used to be able to find good info from your blog articles. acer repair center bangalore
ReplyDeleteThanks for sharing it.I got Very valuable information from your blog.your post is really very Informatve. I got Very valuable information from your blog.I’m satisfied with the information that you provide for me.
ReplyDeleteaws course
Great post i must say and thanks for the information. Education is definitely a sticky subject. However, is still among the leading topics of our time. I appreciate your post and look forward to more.
ReplyDeleteExcelR Data Analytics Course
I have a mission that I’m just now working on, and I have been at the look out for such information ExcelR Data Scientist Courses In Pune
ReplyDeleteThis is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck... data science course
ReplyDeleteActually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written.
ReplyDeletePlease check ExcelR Data Science Certification
I have been searching to find a comfort or effective procedure to complete this process and I think this is the most suitable way to do it effectively.
ReplyDeletePlease check ExcelR Data Science Courses
Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeletedata analytics course mumbai