nio « nio « Java I/O Q&A

Home
Java I/O Q&A
1.API
2.batch File
3.binary File
4.class file
5.CSV file
6.deploy
7.Development
8.directory
9.error
10.Excel File
11.File Attribute
12.jar
13.Log
14.Media File
15.nio
16.Operation
17.PDF file
18.PropertyFile
19.serialize
20.text file
21.Windows
22.XML file
23.Zip
Java I/O Q&A » nio » nio 




1. how to send data to client using nio    stackoverflow.com

Is there any simple example for reading data from server and sending the response to client using java NIO socket channel Thanks, Deepak

2. Best model for an NIO implementation?    stackoverflow.com

I'm in the process of converting our java code to use NIO, but I'm not sure of the best way to design it. My initial approach was to create a pool of ...

3. Java's ReadableByteChannelImpl inconsistent behaviour    stackoverflow.com

When I create a channel out of the InputStream with Channels.newChannel(is) java standard library returns a ReadableByteChannelImpl, which is:

   private static class ReadableByteChannelImpl
       ...

4. Java: use NIO with System.in    stackoverflow.com

Is it possible to use NIO with System.in? I would like to somehow treat 'stdin' as a selectable channel. Has anyone found a way to do this?

5. NIO: Send message and then disconnect immediately    stackoverflow.com

In some circumstances I wish to send an error message from a server to client using non-blocking I/O (SocketChannel.write(ByteBuffer)) and then disconnect the client. Assuming I write the full contents ...

6. Strange exception of Httpcore nio in java    stackoverflow.com

    Exception in thread "Thread-0" java.lang.NullPointerException
 at org.apache.http.impl.nio.reactor.AbstractIOReactor.closeActiveChannels(AbstractIOReactor.java:532)
 at org.apache.http.impl.nio.reactor.AbstractIOReactor.hardShutdown(AbstractIOReactor.java:564)
 at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.doShutdown(AbstractMultiworkerIOReactor.java:411)
 at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:340)
 at com.***.clawer.Clawer$1.run(Clawer.java:81)
 at java.lang.Thread.run(Unknown Source)
    Exception in thread "Thread-1" java.lang.IllegalStateException: I/O ...

7. Java programs using NIO framework    stackoverflow.com

I am doing some research related to Java NIO. I need to find some representative applications that are based on this framework. Please feel free to suggest! The more, the merrier! ...

8. Apache MINA NIO connector help    stackoverflow.com

I'm new to using MINA. I've a program which uses MINA NIOconnector to connect to host. I'm able to send data and also receive. This is clear from log4j log which i'm attaching ...

9. Why use Java's AsynchronousFileChannel?    stackoverflow.com

I can understand why network apps would use multiplexing (to not create too many threads), and why programs would use async calls for pipelining (more efficient). But I don't understand the ...





10. Java: GatheringByteChannel advantages?    stackoverflow.com

I'm wondering when the GatheringByteChannel's write methods (taking in an array of ByteBuffers) have advantages over the "regular" WritableByteChannel write methods. I tried a test where I could use ...

11. Is this the right way to write a ProtocolDecoder in MINA?    stackoverflow.com

public class CustomProtocolDecoder extends CumulativeProtocolDecoder{
byte currentCmd = -1;
int currentSize = -1;
boolean isFirst = false;
@Override
protected boolean doDecode(IoSession is, ByteBuffer bb, ProtocolDecoderOutput pdo) throws Exception {
        ...

12. Java RTP/RTCP library using NIO    stackoverflow.com

Is there a Java RTP/RTCP library based on Java NIO or some Java NIO framework (Netty, MINA, ...)?

13. understanding Java NIO concepts    stackoverflow.com

Can someone suggest a good book/tutorial to understand Java NIO from the operating system perspective (in comparison with java.io?)

14. How do I declare a variable that contains a subclass of a class which implements an interface?    stackoverflow.com

I want to declare a variable which holds a class which implements a specific interface. Specifically, I'm trying to store a SocketChannel and a DatagramChannel in the same property so ...

15. Can I use Java NIO2?    stackoverflow.com

I am working on a project where I've to implement Distributed File System, so for I/O operations, I was thinking of using NIO2 (JDK7) JDK7 will be

16. Need help making this code more efficient    stackoverflow.com

I always use this method to easily read the content of a file. Is it efficient enough? Is 1024 good for the buffer size?

public static String read(File file) {
   ...





17. Java NIO, to use or not to use a framework?    stackoverflow.com

I'm developing a Java Based server, with NIO multiplex and I started to see a lot of frameworks... I don't understand if these frameworks makes the life easier only or has ...

18. Use String or Object for data in Java NIO-based distributed system?    stackoverflow.com

I am trying to send data different data (Security keys, encrypted message )in distributed system that use Java NIO. my question is what is the best way to send data? . ...

19. Access running java program from shell command    stackoverflow.com

I am looking for a way to access running java program from command line. The best woud be something that does the following: Starting java app:

bash$java -jar MyBundle.jar App
Accessing app:
bash$test.sh param1 param2
So, ...

20. java NIO.2 glob problem    stackoverflow.com

I have:

Path path = Paths.get("Foo.class");
Path path2 = Paths.get("Foo.java");

FileSystem fs = FileSystems.getDefault();
PathMatcher matcher = fs.getPathMatcher("glob:*.{class, java}"); 

matcher.matches(path); // TRUE
matcher.matches(path_2); // FALSE
Why path2 is false if the glob syntax {} means that it ...

21. Get file/directory size using Java 7 new IO    stackoverflow.com

How can I get the size of a file or directory using the new NIO in java 7?

22. Apache Mina NioAcceptor    stackoverflow.com

I am experimenting with Apache Mina and currently have unclear point: In NioSocketAcceptor acceptor = new NioSocketAcceptor(2); I specify the number of acceptors. As fa as I ...

23. How to refactor this IO code?    stackoverflow.com

I need to read records from a flat file, where each 128 bytes constitutes a logical record. The calling module of this below reader does just the following.

while(iterator.hasNext()){
   ...

24. NPE at sun.nio.ch.Util.free(Util.java:199)    stackoverflow.com

We are using a third party application which uses sun.nio package. We are facing following error very frequently,

java.lang.NullPointerException
    at sun.nio.ch.Util.free(Util.java:199)
    at sun.nio.ch.Util.offerFirstTemporaryDirectBuffer(Util.java:176)
   ...

25. recommend a book about java io and java nio    stackoverflow.com

I want to dive into java io and java nio, I am looking for some good materials to study. Do you have some good advice to me , good io blogs ...

26. With Java NIO, how do you distinguish between clients?    stackoverflow.com

This may be a terribly naive question but I was just wondering if the client would have to send a "client id" of some sort along with every packet to be ...

27. How can I generate 'un-mappable' input for a Java CharsetDecoder?    stackoverflow.com

I'm writing a set of unit tests for a text decoding class. I'd like to write a test that correctly exercises the handling of un-mappable input to a CharsetDecoder. However, I've ...

28. NIO non-blocking mode    stackoverflow.com

One of the most important aspects of NIO is the ability to operate in non-blocking mode, denied to the traditional java I/O library. But what is non-blocking mode?

29. Why java.nio    coderanch.com

31. Java NIO error (anyone?)    coderanch.com

I get the following error whenever I try to use NIO to copy certain files. Has anyone seen this.. java.io.IOException: Bad address at sun.nio.ch.FileDispatcher.pwrite0(Native Method) at sun.nio.ch.FileDispatcher.pwrite(FileDispatcher.java:46) at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:96) at sun.nio.ch.IOUtil.write(IOUtil.java:60) at sun.nio.ch.FileChannelImpl.write(FileChannelImpl.java:397) at sun.nio.ch.FileChannelImpl.transfer(FileChannelImpl.java:330) at sun.nio.ch.FileChannelImpl.transferFrom(FileChannelImpl.java:316) Code -------- try { // Create channel on the source FileChannel srcChannel = new FileInputStream("srcFilename").getChannel(); // Create channel on the destination FileChannel dstChannel = ...

32. Question about NIO    coderanch.com

33. NIO: Impact on original I/O libraries    coderanch.com

I have just read the following in Manning's JDK1.4 Tutorial (Greg M. Travis) : "...to a substantial degree, the original I/O libraries have been rewritten to take advantage of the New I/O API" I know, for instance, I can obtain a FileChannel from a RandomAccessFile, but does the above mean that the existing methods of RandomAccessFile have been reimplemented to internally ...

34. NIO and Internationalization    coderanch.com

35. NIO and backward compatability with SDK 1.3    coderanch.com

No. Because there is no backward compatability. NIO is an integral part of the base 1.4 Java platform. It cannot be used independently because much of it is implemented in the low-level plumbing of the JVM itself. If you make the decision to use NIO, you're committed to 1.4 - there's no going back. I think this is one reason many ...

36. my post to win a free Java NIO book...    coderanch.com

37. Ron Hitchens' Java NIO book    coderanch.com

I looked at the description on Amazon and it sounds good. Does it have lots of code examples too? Most O'Reilly books are really great with that (with a few exceptions) and it's always very helpful for me. Is there a way to use regular expressions to create a filter (wrapper) for the stream in 1.4? Or do you have to ...

40. Java NIO vs. traditional IO.    coderanch.com

41. NIO    coderanch.com

No, at least not any time soon. The name "New I/O" is rather unfortunate. NIO is not a replacement for the old I/O classes. Rather, it's an alternate way of performing I/O. The older classes in java.io are very powerful and flexible. The compositional patterns they enable work for a broad range of applications. Unfortunately, the stream metaphor used throughout java.io ...

42. Portability implications for NIO    coderanch.com

43. Writing objects over nio    coderanch.com

ByteBuffers and channels deal only with arrays of bytes, they have no conception of things like ObjectStreams. Sending a serialized object graph over an NIO channel is no different than sending any other chunk of bytes. You just need to obtain the bytes representing your serialized object and write it to the channel. Here are two ways to do so: ByteArrayOutputStream ...

44. NIO:Selling point of the Java NIO    coderanch.com

45. NIO DatagramChannels    coderanch.com

46. NIO Book Required    coderanch.com

Hi all java Gurus , I have worked on I/O jdk1.3, Now after a long time again i am starting working on NIO. Please suggest me the best Book on "NIO" to the point with healhy stuff. Currently best book for over all java (2SE v1.4), covering new features or enhancements provided in jdk1.4 by SUN. In time reply will be ...

47. Help about nio...    coderanch.com

Hello friends , I am back to you all experts to get some more things clarified. Well cud anyone tell me the list of differences between java.io package and the java.nio packages ?? One thing which is very much clear to me is that java.nio is more faster that java.io ?? but i wanna know more of it .. i hope ...

48. Some doubt abt NIO usage ?    coderanch.com

If you can do useful processing while waiting for more data to arrive over the network, non-blocking is a hnday way to just grab whatever data is available and continue processing. A more common use is in high-load servers. With blocking IO you need to spawn a new thread for each request which limits the number of simultanious request the server ...

49. Bunch of NIO questions    coderanch.com

Hello, I'm fairly new to NIO, but I do see its benefits. Yet, I still have some questions regarding real world use. For starters, if you drop all advertizements and sale points and theory - how much better is it? has anyone rewritten multiclient socket apps and seen dramatic performance improvements? Also, I have this server that sends out streaming data ...

50. NIO problem.    coderanch.com

Hi, Just playing with NIO for the first time and I am reading from text files from a collection of file objects and the reads always result in: ??? Where as if I read the same files with the old Java IO I get the actual text. My code: FileInputStream inFile = null; try { inFile = new FileInputStream(files[i]); } catch(FileNotFoundException ...

51. NIO Stability    coderanch.com

Hi, I am at a crossroads in deciding the I/O package I have to use in my current project. We are using Sun JVM 1.4.2 and I wanted to know how stable NIO is at present. I know its been around for a while (> 1 year), but I wanted to know if someone has this in production handling huge amount ...

52. convert java.nio to equivalent in 1.3    coderanch.com

Hello, My problem is as follows. I have an application developed under java 1.4 that uses java.nio (available in 1.4 only). I have to make this application compatible for java 1.3 (due to the device it has to run on: PDA). I would really like to avoid rewriteing the application without using java.nio. So I am thinking at either an alternative ...

53. Is NIO really faster than java.io.*    coderanch.com

Hi, I have always used the java.io. classes for java IO. I tried to compare the performance of the io and nio classes FileChannel and ByteBuffers with the normal FileInput/OutputStreams and found that the normal java io was faster than nio. I wrote a simple program that reads a file into a ByteBuffer/Byte Array and writes the output to a FileOutputStream/ByteBuffer. ...

54. nio download problem    coderanch.com

I am using nio to download a file given from a web address. I have not conducted extensive testing but my code works for text files and zip files, but NOT exe or bin files. I assume it works for all text and no binary (although zip is binary right?). The weird thing is, I set up tomcat, and I can ...

55. nio maxing CPU usage    coderanch.com

This post is related to my other post, http://www.coderanch.com/t/277651/Streams/java/nio-download, but now I have a new problem. The code below works, pulls down a file, rips out the http response, and closes the channels properly. HOWEVER, my cpu usage is 100% max while the code runs. This code is also in a thread spawned by a download manager. I have an AMD64 ...

56. java nio usefull for...    coderanch.com

57. io vs nio debate continues    coderanch.com

HI there, I once created a client/server application and used ObjectInputStream and ObjectOutputStream to move the object data back and forth. This worked well. I'm now considering that since the client/server application will soon include VoiP and video streaming, that a faster server using NIO may help increase performance and help get rid of those herky-jerky video images. My understanding of ...

58. nio and getRuntime()?    coderanch.com

Well, Runtime (or rather, Process) doesn't have any special hook for NIO, so you'd have to use the InputStreams and put wrappers around them: Process proc = Runtime.getRuntime().exec(command); ReadableByteChannel standardChannel = Channels.newChannel(proc.getInputStream()); ReadableByteChannel errorChannel = Channels.newChannel(proc.getErrorStream()); What you do with them after that is up to you - they work like other NIO classes, if you have examples of those. As ...

60. NIO in Java SE 6    coderanch.com

61. Text search and replacement using nio    coderanch.com

Hi All, I want to search a particular text ina file and replace it with a different string (much more in length). I am tryinh it with regular expression and new io. here is my code snippet ..................................... RandomAccessFile raf=new RandomAccessFile(f,"rw"); FileChannel fc = raf.getChannel(); int len=(int)fc.size(); MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_WRITE, 0, len); Charset charset = Charset.forName("US-ASCII"); CharsetDecoder decoder = charset.newDecoder(); ...

62. Java nio    coderanch.com

Java nio (I/O and Streams forum at JavaRanch) A friendly place for programming greenhorns! Register / Login Java Forums Java I/O and Streams Java nio Post by: jubin kart, Greenhorn on Jul 19, 2008 13:25:00 Hi, I was trying out java nio and I wanted to see the difference between nio and the normal file stream. I tried copying ...

64. NIO question    coderanch.com

I have write a new NIO server thread, which accept messages from client, but there is some problem. which make it loop too much quickly which make cpu usage to 100%, my run method is follow, any problem? public void run() { try { // This map is used to store clientChannel - Connection pair set, // store it while accepting ...

65. NIO MalformedInputException & German Umlauts    coderanch.com

Hello, I have an NIO server and wish to send messages containing german umlauts such as , , . This works fine on the local development machine but on the internet server it throws an Excpetion: java.nio.charset.MalformedInputException: Input length = 1 at java.nio.charset.CoderResult.throwException(Unknown Source) at java.nio.charset.CharsetDecoder.decode(Unknown Source) I am using 1.5.0_06 on the server and 1.5.0_07 locally. The server is also ...

66. java nio usefull for...    coderanch.com

67. java.nio and Selctor    coderanch.com

Hi all I am trying to understand how java.nio with Async non blocking chanels. Basicly I am going to have to write a server that opens up a port and allows many different clients stream data to it to be processed. I have seen some examples, and I have gotton them to work some, but I want to understand what they ...

68. nio API    coderanch.com

Does the new IO API have a better way of dealing with directories? For example, how do you get the size of a directory? In 1.3, you have to get the size of every file in it. Is there a better way now? Another example: In 1.3. when getting a list of all files in a directory(including all subdirectories) you have ...

69. J2SE 5.0 and NIO    coderanch.com

I'm reading Ivan Horton's Java 2 JDK 5 edition. I just went through the chapters on reading and writing files. He ony covers the new nio classes (FileChannels, ByteBuffers and the various view buffers) and states that he won't cover using streams directly because the new nio methodolgy will supercede using streams directly. After learning the new nio stuff, I can ...

70. Java NIO    coderanch.com

71. NIO NIO NIO    coderanch.com

Hey, I'm doing several networking tests with NIO and I have the following issue: I'm trying to send bytes with a gathering write ( write of bytebuffer array) and I see that my client sends alot of bytes but my client reads much less. Its like the Selector is not fast enough, and it misses some of the selecting. Anyone had ...

72. java nio    coderanch.com

73. NIO vs IO    coderanch.com

Hi All, I have read one tutorial on New IO package of Java. It says that Java NIO is faster than the old IO API. I have tried to find the difference between them using below programs package com.nio.chapter; import java.io.FileInputStream; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; public class NIOReader { public void readFromFile() { try { FileInputStream fis = new FileInputStream( "file.txt" ...

74. NIO 2    coderanch.com

You should probably try googling for such resources. There probably won't be that many yet, since NIO 2 is still pretty new. For detail, I suggest you click my second link and read the documentation of the java.nio.file.* package. In my own code, I haven't changed much since NIO 2 came, except that I'm dropping the File class where I can, ...

75. Helo need for Java NIO    dbforums.com

String ss = "56"; String mm = "07"; String HH = "15"; String DD = "20" ; String MM = "01"; String yy1 = "09"; String yy2 = "20"; String[] dateByteFormat = new String[7]; dateByteFormat[0] = ss; dateByteFormat[1] = mm; dateByteFormat[2] = HH; dateByteFormat[3] = DD; dateByteFormat[4] = MM; dateByteFormat[5] = yy1; dateByteFormat[6] = yy2; for (int i = 0; i

76. IO versus NIO    forums.oracle.com

Hi all, Wow a new look to this forum!!!! I was goin g through the IO and NIO packages in java.I understand that the new nio package as can do all the thing likethe old IO package but its a bit complex as compare to the old one.I am wondering mostly I see people using (even on this forum) new IO ...

78. Why does sun.nio.ch.Net.connect throw BindException?    forums.oracle.com

You are running out of local ports. That can happen by opening large numbers of outbound connections within a two minute time period, which brings TIME_WAIT into play. The solution is simple: don't do that. It should only arise in testing, and all that that means is that you're testing an unrealistic situation, so don't test it. If it arises in ...

79. NIO libs    forums.oracle.com

This might be a stretchy question, but what are the names of the native library needed for NIO to work? I want to know because the first time you create any NIO channel it takes around 500ms which I've been told is the native libs loading, and I'd like to do this at startup instead of the first NIO call. Thanks. ...

80. Java NIO    forums.oracle.com

81. Need to Save String value using Java nio    forums.oracle.com

The 7 byte is saving but all are in HEX format. It want to save these 7 byte exactly same value not in HEX in the file. can u please help me? need to save in file exactly in selected position as per attachment. 56 07 15 20 01 09 20 Please help me.

82. java.nio.charset enconding special characters    forums.oracle.com

83. NIO question    forums.oracle.com

A quick question here. In my program I use NIO filechannel to open big, binary file. Since I don't need to open whole file at once, I just move the position of this filechannel to the point, then read specified size. It works fine, now I was asked if it still works for really big file, >2g. Since I don't have ...

84. Is this bug in java.nio?    forums.oracle.com

But it is not working for me(means it is acting as a shared lock). Really? Can you really acquire two of these exclusive locks on the same file from separate JVMs at the same time? If so that would be a pretty major bug. Strange it hasn't been reported really. Possibly you mean you can still open the file, or you ...

85. Java Nio Problem    forums.oracle.com

86. Writing Objects using java.nio    forums.oracle.com

87. Using NIO or IO?    forums.oracle.com

I have made a Live Online Chat program and have been having a few strange issues that have caused the connections to reset and disconnect the chat session. (e.g. java.net.SocketException: Software caused connection abort: socket write error) I am wondering if this is because I'm using IO over NIO. Currently, my program sends many Objects back and forth using ObjectInputStream and ...

88. NIO verses IO    forums.oracle.com

Before starting to write down anything go and look. I've been working in a java project using sockts, the project took 8 months and during that time we did test in order to decide what to use... NIO offers more functionaty out of the box, and that off course leads to a bigger code complexety, not in the end code of ...

89. java.nio read/write question    forums.oracle.com

A number of the regular posters here are striking in protest at the poor management of these forums. Although it is our unpaid efforts which make the forums function, the Sun employees responsible for them seem to regard us as contemptible. We hope that this strike will enable them to see the value which we provide to Sun. Apologies to unsuspecting ...

90. java.nio.charset.spi.CharsetProvider problem    forums.oracle.com

sun.misc.ServiceConfigurationError: java.nio.charset.spi.CharsetProvider: jar:file:/C:/Program Files/Java/j2re1.4.2_12/lib/charsets.jar!/META-INF/services/java.nio.charset.spi.CharsetProvider:1: Illegal configuration-file syntax at sun.misc.Service.fail(Unknown Source) at sun.misc.Service.fail(Unknown Source) at sun.misc.Service.parseLine(Unknown Source) at sun.misc.Service.parse(Unknown Source) at sun.misc.Service.access$100(Unknown Source) at sun.misc.Service$LazyIterator.hasNext(Unknown Source) at java.nio.charset.Charset$1.getNext(Unknown Source) at java.nio.charset.Charset$1.hasNext(Unknown Source) at java.nio.charset.Charset$2.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.nio.charset.Charset.lookupViaProviders(Unknown Source) at java.nio.charset.Charset.lookup2(Unknown Source) at java.nio.charset.Charset.lookup(Unknown Source) at java.nio.charset.Charset.isSupported(Unknown Source) at sun.nio.cs.StreamDecoder.forInputStreamReader(Unknown Source) at java.io.InputStreamReader.(Unknown Source) Does anyone know a solution? Thanks ...

91. Java NIO Question    forums.oracle.com

Hello, I am developing a java nio based chat application with encoded secure communication. Logging in to the server and initiating the whole cipher things works fine. So the communication between client and server is encoded. The whole architecture works fine, when I have the following approach: Client writes to -> Server response to -> Client But I want to develop ...

92. java nio    forums.oracle.com

93. NIO Simultaneous read and write operation    forums.oracle.com

No, it is that you have to get your buffer positions and limits and flips and rewinds organized. mb.put(bb) just puts the entire contents of bb into mb starting from the current position, and if bb won't fit between position and limit you'll get an overflow. You probably need to reset or rewind the buffer so position = zero and limit ...

94. java.nio: scatter-gather question    forums.oracle.com

Hi, i have a question on the following scatter-gather java.nio code. What happens if a message is smaller in size than the (maximum) "messageLength" -if the messages are not of fixed size? The check "(bytesRead < messageLength) " won't work and we will start storing bytes from the next message in the buffer

95. Where I can find good Java NIO tutorial?    forums.oracle.com

96. New to NIO and ByteOrder. How do I read in Little Endian?    forums.oracle.com

Hi. About a year ago I wrote a class for reading little-endian files with the IO library where I had to convert the bytes from little-endian with bit shifting. I see that NIO has a ByteOrder class for specifying endianness. Ive also heard that its "faster" and "better". I have 30 megs files so that would be nice. Im having no ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.