Java NIO - copy-on-write buffer

This is regarding peculiar behavior of a Java program on Linux-IA64 platform.
I have a Java program that uses MappedByteBuffer. For the same file, there are three buffers - read only, read/write and copy-on-write (cow)
First, change contents of cow buffer and print all buffers. The change is reflected only in cow buffer (not in ro or rw) - as expected.
Then, change contents of r/w buffer and print all buffers. The change is NOT observed in cow buffer, but reflected in ro and rw buffers (for Linux-IA64). I tried the same program in Linux-X86 and the change is reflected in all buffers (including cow buffer).
I used JDK 1.4.2_03 for compiling and running. The doc for MappedByteBuffer says
"The content of a mapped byte buffer can change at any time, for example if the content of the corresponding region of the mapped file is changed by this program or another. Whether or not such changes occur, and when they occur, is operating-system dependent and therefore unspecified."
Is this behaviour acceptable? Is this observed in any other platform?
I think Java NIO leaves it to the O/S and JVM is not doing anything here (as different from java.io). This could probably result in inconsistent behaviour across platforms (though it improves performance)
Please let me know your thoughts.

My thought is that you have posted this to the wrong forum.

Similar Messages

  • Java.nio.channels.IllegalBlockingModeException

    I am using selector for read and PrintWriter writer = new PrintWriter(new OutputStreamWriter(sc.getOutputStream()),true) for writing to the socket and I get this exception at write statement. Can anyone suggest me what should I do??
    java.nio.channels.IllegalBlockingModeException
    at java.nio.channels.Channels.write(Channels.java:59)
    at java.nio.channels.Channels.access$000(Channels.java:47)
    at java.nio.channels.Channels$1.write(Channels.java:134)
    at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:334)
    at sun.nio.cs.StreamEncoder$CharsetSE.implFlushBuffer(StreamEncoder.java
    :402)
    at sun.nio.cs.StreamEncoder$CharsetSE.implFlush(StreamEncoder.java:406)
    at sun.nio.cs.StreamEncoder.flush(StreamEncoder.java:150)
    at java.io.OutputStreamWriter.flush(OutputStreamWriter.java:213)
    at java.io.PrintWriter.newLine(PrintWriter.java:256)
    at java.io.PrintWriter.println(PrintWriter.java:405)
    at java.io.PrintWriter.println(PrintWriter.java:516)
    at SktChannelTest3.run(SktChannelTest3.java:91)

    Hi,
    Thanx for the reply. I am using Selecotor for read and if it timesout I used PrintWriter to write to Socket ( Not socket channel). So, once it comes out of select loop, it'd excecute PrintWriter.println("Timeout message....") statement. And at this statement I/m getting exception.

  • Java.nio read/write question

    Hello,
    I just started to learn the java.nio package so I decided to make a simple Echo server. I made a client which reads a line from the keyboard, sends it to the server and the server returns it. It all works except one little detail. Here's little code from the server:
                                 int n = client.read(buffer);
                                 if ( n > 0)
                                     buffer.flip();
                                     client.write(buffer);
                                     Charset charset = Charset.forName("ISO-8859-1");
                                     CharsetDecoder decoder = charset.newDecoder();
                                     charBuffer = decoder.decode(buffer);
                                     System.out.println(charBuffer.toString());
                                     buffer.clear();
                                  }So that works, I send the data and then I receive it back. But only for the client. I also wanted the server to print the line which is the reason for the charset and the decoder. The above code however prints only a blank line. Thus I tried this:
                                 int n = client.read(buffer);
                                 if ( n > 0)
                                     buffer.flip();
                                     Charset charset = Charset.forName("ISO-8859-1");
                                     CharsetDecoder decoder = charset.newDecoder();
                                     charBuffer = decoder.decode(buffer);
                                     System.out.println(charBuffer.toString());
                                     client.write(buffer);
                                     buffer.clear();
                                  }Or in other words I just moved the write() part downwards. So far so good, now the server was actually printing the lines that the client was sending but nothing was sent back to the client.
    The question is how to make both, the send back line and the print line on the server side to work as intended. Also a little explanation why the events described above are happening is going to be more than welcome :)
    Thanks in advance!

    Strike notice
    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 innocents caught up in
    the cross-fire.

  • Files.copy java.nio.file.AccessDeniedException

    Hello everybody,
    I hope you are well, Me not.
    I use this method to unzip
    public void deziper(final Path zipFile, final Path destDir) throws IOException*
              // On crée un FileSystem associé à l'archive :
         try ( FileSystem zfs = FileSystems.newFileSystem(zipFile, null) ) {
         // On parcourt tous les éléments root :
         for (Path root : zfs.getRootDirectories()) {
         // Et on parcourt toutes leurs arborescences :
         Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
         private Path unzippedPath(Path path) {
    return Paths.get(destDir.toString(), path.toString()).normalize();
         @Override
         public FileVisitResult preVisitDirectory(Path dir,
         BasicFileAttributes attrs) throws IOException {
         // On crée chaque répertoire intermédiaire :
         Files.createDirectories(unzippedPath(dir));
         return FileVisitResult.CONTINUE;
         @Override
         public FileVisitResult visitFile(Path file,
         BasicFileAttributes attrs) throws IOException {
         // Et on copie chaque fichier :
         Files.copy(file, unzippedPath(file), StandardCopyOption.COPY_ATTRIBUTES, StandardCopyOption.REPLACE_EXISTING);
         return FileVisitResult.CONTINUE;
    Replace all files work well, but when application try to replace Executable Jar File in same directory This error is thrown
    09oct.2012 13:52:12,484 - 0 [AWT-EventQueue-0] WARN barakahfx.ModuleUpdater - Exception
    java.nio.file.AccessDeniedException: G:\Program Files\Djindo\Imanis\Djindo.jar
         at sun.nio.fs.WindowsException.translateToIOException(Unknown Source)
         at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
         at sun.nio.fs.WindowsException.rethrowAsIOException(Unknown Source)
         at sun.nio.fs.WindowsFileSystemProvider.implDelete(Unknown Source)
         at sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(Unknown Source)
         at java.nio.file.Files.deleteIfExists(Unknown Source)
         at java.nio.file.CopyMoveHelper.copyToForeignTarget(Unknown Source)
         at java.nio.file.Files.copy(Unknown Source)
         at lib.GererFichier$3.visitFile(GererFichier.java:167)
         at lib.GererFichier$3.visitFile(GererFichier.java:150)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.FileTreeWalker.walk(Unknown Source)
         at java.nio.file.Files.walkFileTree(Unknown Source)
         at java.nio.file.Files.walkFileTree(Unknown Source)
         at lib.GererFichier.deziper(GererFichier.java:150)
         at barakahfx.ModuleUpdater.demarrerUpdate(ModuleUpdater.java:98)
         at barakahfx.AppliCtrl.demarrer(AppliCtrl.java:92)
         at barakahfx.BarakahFx$1.actionPerformed(BarakahFx.java:56)
         at javax.swing.Timer.fireActionPerformed(Unknown Source)
         at javax.swing.Timer$DoPostEvent.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
         at java.awt.EventQueue.access$200(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.awt.EventQueue$3.run(Unknown Source)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    Thank you very match
    Edited by: 964115 on Oct 9, 2012 5:39 AM
    Edited by: 964115 on Oct 9, 2012 5:40 AM
    Edited by: 964115 on Oct 9, 2012 5:46 AM
    Edited by: 964115 on Oct 9, 2012 5:55 AM

    Looks like you are trying to move the jar file you are executing and Windows has placed a lock on it. As far as I am aware there is no simple way round this. Why do you think you need to do this?

  • Java NIO client

    I need to make the server is able to hold about 500 connections and operates on a single thread. The server itself should make all the connections. Where can I find examples of finished implementations?

    I have an example, but it does not work
    import java.io.IOException;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.Socket;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.nio.channels.spi.SelectorProvider;
    import java.util.*;
    public class NioClient implements Runnable {
         // The host:port combination to connect to
         private InetAddress hostAddress;
         private String host;
         private int port;
         // The selector we'll be monitoring
         private Selector selector;
         // The buffer into which we'll read data when it's available
         private ByteBuffer readBuffer = ByteBuffer.allocate(8192);
         // A list of PendingChange instances
         private List pendingChanges = new LinkedList();
         // Maps a SocketChannel to a list of ByteBuffer instances
         private Map pendingData = new HashMap();
         // Maps a SocketChannel to a RspHandler
         private Map rspHandlers = Collections.synchronizedMap(new HashMap());
         public NioClient() {
              try {this.selector = this.initSelector();} catch(IOException e){}
         public void connect(String host, int port, RspHandler handler) throws IOException {
              this.hostAddress = hostAddress;
              this.host = host;
              this.port = port;
              this.send("$Hello |".getBytes(), handler);
         public void send(byte[] data, RspHandler handler) throws IOException {
              // Start a new connection
              SocketChannel socket = this.initiateConnection();
              // Register the response handler
              this.rspHandlers.put(socket, handler);
              // And queue the data we want written
              synchronized (this.pendingData) {
                   List queue = (List) this.pendingData.get(socket);
                   if (queue == null) {
                        queue = new ArrayList();
                        this.pendingData.put(socket, queue);
                   queue.add(ByteBuffer.wrap(data));
              // Finally, wake up our selecting thread so it can make the required changes
              this.selector.wakeup();
              handler.waitForResponse();
         public void run() {
              while (true) {
                   try {
                        // Process any pending changes
                        synchronized (this.pendingChanges) {
                             Iterator changes = this.pendingChanges.iterator();
                             while (changes.hasNext()) {
                                  ChangeRequest change = (ChangeRequest) changes.next();
                                  switch (change.type) {
                                  case ChangeRequest.CHANGEOPS:
                                       SelectionKey key = change.socket.keyFor(this.selector);
                                       key.interestOps(change.ops);
                                       break;
                                  case ChangeRequest.REGISTER:
                                       change.socket.register(this.selector, change.ops);
                                       break;
                             this.pendingChanges.clear();
                        // Wait for an event one of the registered channels
                        this.selector.select();
                        // Iterate over the set of keys for which events are available
                        Iterator selectedKeys = this.selector.selectedKeys().iterator();
                        while (selectedKeys.hasNext()) {
                             SelectionKey key = (SelectionKey) selectedKeys.next();
                             selectedKeys.remove();
                             if (!key.isValid()) {
                                  continue;
                             // Check what event is available and deal with it
                             if (key.isConnectable()) {
                                  this.finishConnection(key);
                             } else if (key.isReadable()) {
                                  this.read(key);
                             } else if (key.isWritable()) {
                                  this.write(key);
                   } catch (Exception e) {
                        e.printStackTrace();
         private void read(SelectionKey key) throws IOException {
              SocketChannel socketChannel = (SocketChannel) key.channel();
              // Clear out our read buffer so it's ready for new data
              this.readBuffer.clear();
              // Attempt to read off the channel
              int numRead;
              try {
                   numRead = socketChannel.read(this.readBuffer);
              } catch (IOException e) {
                   // The remote forcibly closed the connection, cancel
                   // the selection key and close the channel.
                   key.cancel();
                   socketChannel.close();
                   return;
              System.out.println("READ");
              if (numRead == -1) {
                   // Remote entity shut the socket down cleanly. Do the
                   // same from our end and cancel the channel.
                   key.channel().close();
                   key.cancel();
                   return;
              // Handle the response
              this.handleResponse(socketChannel, this.readBuffer.array(), numRead);
         private void handleResponse(SocketChannel socketChannel, byte[] data, int numRead) throws IOException {
              // Make a correctly sized copy of the data before handing it
              // to the client
              byte[] rspData = new byte[numRead];
              System.arraycopy(data, 0, rspData, 0, numRead);
              // Look up the handler for this channel
              RspHandler handler = (RspHandler) this.rspHandlers.get(socketChannel);
              // And pass the response to it
              if (handler.handleResponse(rspData)) {
                   // The handler has seen enough, close the connection
                   socketChannel.close();
                   socketChannel.keyFor(this.selector).cancel();
         private void write(SelectionKey key) throws IOException {
              SocketChannel socketChannel = (SocketChannel) key.channel();
              synchronized (this.pendingData) {
                   List queue = (List) this.pendingData.get(socketChannel);
                   // Write until there's not more data ...
                   while (!queue.isEmpty()) {
                        ByteBuffer buf = (ByteBuffer) queue.get(0);
                        socketChannel.write(buf);
                        if (buf.remaining() > 0) {
                             // ... or the socket's buffer fills up
                             break;
                        queue.remove(0);
                   if (queue.isEmpty()) {
                        // We wrote away all data, so we're no longer interested
                        // in writing on this socket. Switch back to waiting for
                        // data.
                        key.interestOps(SelectionKey.OP_READ);
         private void finishConnection(SelectionKey key) throws IOException {
              SocketChannel socketChannel = (SocketChannel) key.channel();
              // Finish the connection. If the connection operation failed
              // this will raise an IOException.
              try {
                   socketChannel.finishConnect();
              } catch (IOException e) {
                   // Cancel the channel's registration with our selector
                   System.out.println(e);
                   key.cancel();
                   return;
              // Register an interest in writing on this channel
              key.interestOps(SelectionKey.OP_WRITE);
         private SocketChannel initiateConnection() throws IOException {
              // Create a non-blocking socket channel
              SocketChannel socketChannel = SocketChannel.open();
              socketChannel.configureBlocking(false);
              // Kick off connection establishment
              socketChannel.connect(new InetSocketAddress(this.host, this.port));
              // Queue a channel registration since the caller is not the
              // selecting thread. As part of the registration we'll register
              // an interest in connection events. These are raised when a channel
              // is ready to complete connection establishment.
              synchronized(this.pendingChanges) {
                   this.pendingChanges.add(new ChangeRequest(socketChannel, ChangeRequest.REGISTER, SelectionKey.OP_CONNECT));
              return socketChannel;
         private Selector initSelector() throws IOException {
              // Create a new selector
              return SelectorProvider.provider().openSelector();
    public class RspHandler {
         private byte[] rsp = null;
         public synchronized boolean handleResponse(byte[] rsp) {
              this.rsp = rsp;
              this.notify();
              return true;
         public synchronized void waitForResponse() {
              while(this.rsp == null) {
                   try {
                        this.wait();
                   } catch (InterruptedException e) {
              System.out.println(new String(this.rsp));
    }          NioClient NioClient = new NioClient();
              Thread t = new Thread(NioClient);
              t.setDaemon(true);
              t.start();
              RspHandler handler = new RspHandler();          
              NioClient.connect("69.28.156.250", 27040, handler);
              NioClient.connect("72.165.61.188", 27040, handler);
              NioClient.connect("208.111.133.84", 27011, handler);
              NioClient.connect("72.165.61.136", 27012, handler);
    Edited by: 915967 on 01.08.2012 7:07

  • Performance of java nio with dd in linux.

    Hi
    I ran this code in java to dump 0s in a file of size 1gb and tried the same with dd in linux.
    Java code : I use a preinitialized array (the data) and fill a mappedbytebuffer with it.
    package filePersistence.test;
    import java.io.File;
    import java.io.RandomAccessFile;
    import java.nio.MappedByteBuffer;
    import java.nio.channels.FileChannel;
    public class TimeLineTest {
         private static final int BYTE_LENGTH = 1000;
         //this is the input
         static byte[] b = new byte[BYTE_LENGTH];
         public static void main(String[] arg) throws Exception
              //initializing the input
              for (int i=0;i<BYTE_LENGTH;i++)
                   b[i] = 0;
              File file = new File(arg[0]);
              RandomAccessFile raFile = new RandomAccessFile(file,"rw");
              FileChannel fChannel = raFile.getChannel();
              int loopCount = 1000000;
              MappedByteBuffer mbuffer = fChannel.map( FileChannel.MapMode.READ_WRITE ,0,loopCount * BYTE_LENGTH);
              //System.out.println(" going to fill in a file" + file.getName());
              long k = 0;
              long startTime = System.currentTimeMillis();
              for (int i=0;i<loopCount;i++)
         //populate the mapped buffer
                   mbuffer.put(b);
              //persist into the file
              mbuffer.force();
              long endTime = System.currentTimeMillis();
              System.out.println(" file filled size1 "+file.length());
              System.out.println(" time " + (endTime - startTime));
    On a linux machine this takes around 7 secs while dd used as
    "dd if=/dev/zero of=mytestfile.out bs=1000 count=1000000"
    1000000+0 records in
    1000000+0 records out
    1000000000 bytes (1.0 GB) copied, 4.618 seconds, 217 MB/s
    4.6 and 7 differ quite a lot. Is there a way the java code can be improved to match dd ?(-sever does not help)
    Thanks
    Sumanta

    Hi
    Can this be called a dd equivalent code ?
    package filePersistence.test;
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.RandomAccessFile;
    import java.nio.MappedByteBuffer;
    import java.nio.channels.FileChannel;
    public class TimeLineTest {
         private static final int BYTE_LENGTH = 1000;
         //this is the input
         static byte[] b = new byte[BYTE_LENGTH];
         public static void main(String[] arg) throws Exception
              //initializing the input
              for (int i=0;i<BYTE_LENGTH;i++)
                   b[i] = 0;
              String srcFile = arg[0] + "_src";
              FileOutputStream fos = new FileOutputStream(srcFile);
              fos.write(b);
              fos.getFD().sync();
              fos.flush();
              fos.close();
              RandomAccessFile srcraFile = new RandomAccessFile(srcFile,"rw");
              FileChannel srcChannel = srcraFile.getChannel();
              File file = new File(arg[0]);
              RandomAccessFile raFile = new RandomAccessFile(file,"rw");
              FileChannel raChannel = raFile.getChannel();
              int loopCount = 1000000;
              //MappedByteBuffer mbuffer = fChannel.map( FileChannel.MapMode.READ_WRITE ,0,loopCount * BYTE_LENGTH);
              //System.out.println(" going to fill in a file" + file.getName());
              long startTime = System.currentTimeMillis();
              for (int i=0,position=0;i<loopCount;i++,position+=BYTE_LENGTH)
         //populate the mapped buffer
                   //mbuffer.put(b);
                   raChannel.position(position);
                   srcChannel.transferTo(0, BYTE_LENGTH, raChannel);
              //persist into the file
              //mbuffer.force();
              raFile.getFD().sync();
              raChannel.close();
              raFile.close();
              long endTime = System.currentTimeMillis();
              System.out.println(" file filled size1 "+file.length());
              System.out.println(" time " + (endTime - startTime));
    }

  • Using java.nio

    I have copied this, one program from a book that would have to read file of gives to me to you mixed but it does not work, you could me why?
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.nio.ByteBuffer;
    import java.nio.channels.FileChannel;
    public class ReadPrimesMixedData {
    public static void main(String[] args) {
    File aFile = new File("C:/Beg Java Stuff/primes.txt");
    FileInputStream inFile = null;
    try {
    inFile = new FileInputStream(aFile);
    } catch(FileNotFoundException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    FileChannel inChannel = inFile.getChannel();
    try {
    ByteBuffer lengthBuf = ByteBuffer.allocate(8);
    int strLength = 0; // Stores the string length
    ByteBuffer buf = null; // Stores a reference to the second byte buffer
    byte[] strChars = null; // Stores a reference to an array to hold the string
    while(true) {
    if(inChannel.read(lengthBuf) == -1) // Read the string length, if its EOF
    break; // exit the loop
    lengthBuf.flip();
    strLength = (int)lengthBuf.getDouble(); // Extract the length and convert to int
    buf = ByteBuffer.allocate(strLength+8); // Buffer for the string & the prime
    if(inChannel.read(buf) == -1) {            // Read the string & binary prime value
    assert false; // Should not get here!
    break; // Exit loop on EOF
    buf.flip();
    strChars = new byte[strLength]; // Create the array for the string
    buf.get(strChars); // Extract string & binary prime value
    System.out.println("String length: " + strChars.length+ " String: " +
    new String(strChars) + " Binary value: " + buf.getLong());
    lengthBuf.clear(); // Clear the buffer for the next read
    System.out.println("\nEOF reached.");
    inFile.close(); // Close the file and the channel
    } catch(IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    System.exit(0);
    This e' the program that writes the file
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.FileChannel;
    public class PrimesToFile2 {
    public static void main(String[] args) {
    int primesRequired = 100; // Default count
    if (args.length > 0) {
    try {
    primesRequired = Integer.valueOf(args[0]).intValue();
    } catch (NumberFormatException e) {
    System.out.println("Prime count value invalid. Using default of "
    + primesRequired);
    long[] primes = new long[primesRequired]; // Array to store primes
    primes[0] = 2; // Seed the first prime
    primes[1] = 3; // and the second
    // Count of primes found - up to now, which is also the array index
    int count = 2;
    long number = 5; // Next integer to be tested
    outer:
    for (; count < primesRequired; number += 2) {
    // The maximum divisor we need to try is square root of number
    long limit = (long) Math.ceil(Math.sqrt((double) number));
    // Divide by all the primes we have up to limit
    for (int i = 1; i < count && primes[i] <= limit; i++)
    if (number % primes[i] == 0) // Is it an exact divisor?
    continue outer; // yes, try the next number
    primes[count++] = number; // We got one!
    File aFile = new File("C:/Beg Java Stuff/primes.txt");
    FileOutputStream outputFile = null;
    try {
    outputFile = new FileOutputStream(aFile);
    } catch (FileNotFoundException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    FileChannel file = outputFile.getChannel();
    final int BUFFERSIZE = 100; // Buffer size in bytes
    ByteBuffer buf = ByteBuffer.allocate(BUFFERSIZE);
    DoubleBuffer doubleBuf = buf.asDoubleBuffer();
    buf.position(8);
    CharBuffer charBuf = buf.asCharBuffer();
    LongBuffer longBuf = null;
    String primeStr = null;
    for (int i = 0; i < primes.length; i++) {
    primeStr = "prime = " + primes; // Create the string
    doubleBuf.put(0,(double) primeStr.length());// Store the string length
    charBuf.put(primeStr); // Store the string
    buf.position(2 * charBuf.position() + 8); // Position for 3rd buffer
    longBuf = buf.asLongBuffer(); // Create the buffer
    longBuf.put(primes[i]); // Store the binary long value
    buf.position(buf.position() + 8); // Set position after last value
    buf.flip(); // and flip
    try {
    file.write(buf); // Write the buffer as before.
    } catch (IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    buf.clear();
    doubleBuf.clear();
    charBuf.clear();
    try {
    System.out.println("File written is " + file.size() + " bytes.");
    outputFile.close(); // Close the file and its channel
    } catch (IOException e) {
    e.printStackTrace(System.err);
    System.exit(1);
    System.exit(0);
    This works correctly

    I don't have problems when I compile the program but if I run the program ....I have this
    String length: 9 String: prim Binary value: 7277852183226228736
    String length: 0 String: Binary value: 162166969980682240
    String length: 0 String: Binary value: 7854388801345436928
    String length: 0 String: Binary value: 3573983215616
    Stjava.lang.IllegalArgumentException
    at java.nio.ByteBuffer.allocate(ByteBuffer.java:303)
    at ReadPrimesMixedData.main(ReadPrimesMixedData.java:35)
    ring length: 0 String: Binary value: 7566167222444367872
    String length: 0 String: Binary value: 88089088
    String length: 0 String: Binary value: 8214681170873443584
    String length: 0 String: Binary value: 1856
    String length: 0 String: Binary value: 8070575878335130880
    Exception in thread "main"

  • Java.nio select() method return 0 in my client application

    Hello,
    I'm developing a simple chat application who echo messages
    But my client application loop because the select() method return 0
    This is my code
    // SERVER
    package test;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    public class Server {
         private int port = 5001;
         public void work() {               
              try {
                   ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();
                   serverSocketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(port);               
                   serverSocketChannel.socket().bind(isa);
                   Selector selector = Selector.open();
                   serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
                   System.out.println("Listing on "+port);
                   while(selector.select()>0) {
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();) {
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isAcceptable()) {
                                  ServerSocketChannel keyChannel = (ServerSocketChannel)key.channel();                              
                                  SocketChannel channel = keyChannel.accept();
                                  channel.configureBlocking(false);                              
                                  channel.register(selector, SelectionKey.OP_READ );
                             } else if (key.isReadable()) {
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  String m = Help.read(keyChannel );
                                  Help.write(m.toUpperCase(), keyChannel );
              } catch (IOException e) {                                             
                   e.printStackTrace();                         
         public static void main(String[] args) {
              Server s = new Server();
              s.work();
    // CLIENT
    package test;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class Client extends JFrame  {
         private String host = "localhost";
         private int port = 5001;
         private SocketChannel socketChannel;
         private Selector selector;
         public void work() {               
              try {
                   socketChannel = SocketChannel.open();
                   socketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(host, port);               
                   socketChannel.connect(isa);
                   selector = Selector.open();
                   socketChannel.register(selector, SelectionKey.OP_CONNECT | SelectionKey.OP_READ );
                   while(true) {
                        selector.select();
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();) {
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isConnectable()) {
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  if (keyChannel.isConnectionPending()) {
                                       System.out.println("Connected "+keyChannel.finishConnect());                                                                           
                             } else if (key.isReadable()) {                                                                                                                                                           
                                  SocketChannel keyChannel = (SocketChannel) key.channel();                                             
                                  String m = Help.read(keyChannel);
                                  display(m);                                                                                                                                                                                                                   
              } catch (IOException e) {                                             
                   e.printStackTrace();                         
         private void display(final String m) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        area.append(m+"\n");
                        textFieed.setText("");
         private void sendMessage(final String m) {
              Thread t = new Thread(new Runnable() {               
                   public void run() {                                                                                
                        try {                         
                             Help.write(m, socketChannel);
                        } catch (IOException e) {               
                             e.printStackTrace();
              t.start();                    
         public Client() {
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(1);
              textFieed.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode()== KeyEvent.VK_ENTER) {
                             String m = textFieed.getText();
                             sendMessage(m);     
              area.setEditable(false);
              getContentPane().add(textFieed, "North");
              getContentPane().add(new JScrollPane(area));
              setBounds(200, 200, 400, 300);
              show();
         private String messageToSend;
         private JTextArea area = new JTextArea();
         JTextField textFieed = new JTextField();
         public static void main(String[] args) {
              Client s = new Client();
              s.work();
    // HELPER CLASS
    package test;
    import java.io.IOException;
    import java.nio.ByteBuffer;
    import java.nio.CharBuffer;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;
    import java.nio.charset.CharsetDecoder;
    import java.nio.charset.CharsetEncoder;
    public class Help {
         private static Charset charset = Charset.forName("us-ascii");
         private static CharsetEncoder enc = charset.newEncoder();
         private static CharsetDecoder dec = charset.newDecoder();
         private static void log(String m) {
              System.out.println(m);
         public static String read(SocketChannel channel) throws IOException {
              log("*** start READ");                              
              int n;
              ByteBuffer buffer = ByteBuffer.allocate(1024);
              while((n = channel.read(buffer)) > 0) {
                   System.out.println("     adding "+n+" bytes");
              log("  BUFFER REMPLI : "+buffer);
              buffer.flip();               
              CharBuffer cb = dec.decode(buffer);          
              log("  CHARBUFFER : "+cb);
              String m = cb.toString();
              log("  MESSAGE : "+m);          
              log("*** end READ");
              //buffer.clear();
              return m;                    
         public static void write(String m, SocketChannel channel) throws IOException {          
              log("xxx start WRITE");          
              CharBuffer cb = CharBuffer.wrap(m);
              log("  CHARBUFFER : "+cb);          
              ByteBuffer  buffer = enc.encode(cb);
              log("  BUFFER ALLOUE REMPLI : "+buffer);
              int n;
              while(buffer.hasRemaining()) {
                   n = channel.write(buffer);                         
              System.out.println("  REMAINING : "+buffer.hasRemaining());
              log("xxx end WRITE");

    Here's the fix for that old problem. Change the work method to do the following
    - don't register interest in things that can't happen
    - when you connect register based on whether the connection is complete or pending.
    - add the OP_READ interest once the connection is complete.
    This doesn't fix all the other problems this code will have,
    eg.
    - what happens if a write is incomplete?
    - why does my code loop if I add OP_WRITE interest?
    - why does my interestOps or register method block?
    For code that answers all those questions see my obese post Taming the NIO Circus
    Here's the fixed up Client code
    // CLIENT
    package test
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.SocketChannel;
    import java.util.Iterator;
    import java.util.Set;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    public class Client extends JFrame  {
         private String host = "localhost";
         private int port = 5001;
         private SocketChannel socketChannel;
         private Selector selector;
         public void work() {
              try {
                   socketChannel = SocketChannel.open();
                   socketChannel.configureBlocking(false);
                   InetSocketAddress isa = new InetSocketAddress(host, port);
                   socketChannel.connect(isa);
                   selector = Selector.open();
                   int interest = 0;
                   if(socketChannel.isConnected())interest = SelectionKey.OP_READ;
                   else if(socketChannel.isConnectionPending())interest = SelectionKey.OP_CONNECT;
                   socketChannel.register(selector, interest);
                   while(true)
                        int nn = selector.select();
                        System.out.println("nn="+nn);
                        Set keys = selector.selectedKeys();
                        for(Iterator i = keys.iterator(); i.hasNext();)
                             SelectionKey key = (SelectionKey) i.next();
                             i.remove();
                             if (key.isConnectable())
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  System.out.println("Connected "+keyChannel.finishConnect());
                                  key.interestOps(SelectionKey.OP_READ);
                             if (key.isReadable())
                                  SocketChannel keyChannel = (SocketChannel) key.channel();
                                  String m = Help.read(keyChannel);
                                  display(m);
              } catch (IOException e) {
                   e.printStackTrace();
         private void display(final String m) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        area.append(m+"\n");
                        textFieed.setText("");
         private void sendMessage(final String m) {
              Thread t = new Thread(new Runnable() {
                   public void run() {
                        try {
                             Help.write(m, socketChannel);
                        } catch (IOException e) {
                             e.printStackTrace();
              t.start();
         public Client() {
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(1);
              textFieed.addKeyListener(new KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        if (e.getKeyCode()== KeyEvent.VK_ENTER) {
                             String m = textFieed.getText();
                             sendMessage(m);
              area.setEditable(false);
              getContentPane().add(textFieed, "North");
              getContentPane().add(new JScrollPane(area));
              setBounds(200, 200, 400, 300);
              show();
         private String messageToSend;
         private JTextArea area = new JTextArea();
         JTextField textFieed = new JTextField();
         public static void main(String[] args) {
              Client s = new Client();
              s.work();

  • [java.nio] StreamCorruptedException when deserializing objects

    Hello everybody!
    I made a messaging (chat) program using java.io where all the client-server communication is done by serializing small objects. Now I would like to covert the server side to the NIO concept and I'm already struck. I successfully pass objects to the client and the client deserializes them, but only the first one! When it try to read the second it fails with a StreamCorruptedException.
    Here�s a sample (testing) code. In the server run() method I first serialize a string, then get its byte array from ByteArrayOutputStream and in the loop periodically send this byte array through the channel. On the client side I just read the deserialized object.
    Server run():
    public void run() {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject("abcdefgh");
                byte[] objectArr = baos.toByteArray();
                baos.close();
                oos.close();
                ByteBuffer buff = ByteBuffer.allocate(objectArr.length);
                buff.put(objectArr);
                buff.flip();
                while(true) {
                    selector.select();
                    Set keys = selector.selectedKeys();
                    for (Object o : keys) {
                        SelectionKey key = (SelectionKey)o;
                        if (key.isAcceptable()) {
                            ServerSocketChannel server = (ServerSocketChannel) key.channel();
                            clientChannel = server.accept();
                            if (clientChannel == null)
                                continue;
                            clientChannel.configureBlocking(false);
                            SelectionKey clientKey = clientChannel.register(selector, SelectionKey.OP_WRITE);
                        } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                    try {
                        Thread.currentThread().sleep(2000);
                    } catch (InterruptedException e) {
                        return;
            } catch (IOException e) {
                e.printStackTrace();
        }Client run():
    public void run() {
            try {
                soc = new Socket("localhost", 4000);
                ObjectInputStream ois = new ObjectInputStream(soc.getInputStream());
                while(true) {
                    Object d = ois.readObject();
                    System.out.println("data = " + d.toString());
            } catch (Exception ex) {
                ex.printStackTrace();
        }At the second read I get a StreamCorruptedException.
    Apart from this I would like some hints in how to implement the application with NIO. For example how can I tell the objects apart on the client side � should I send every time a byte array before the object, which tells the length of the next coming object? This is probably not a 100% bulletproof solution and presents additional data transfer?
    Than you in advance!

    OK, I found a solution but I don't like it, because I don't understand it.
    The ObjectOutputStream adds a header (4 bytes) to the stream - if I send the array with those four bytes I get an StreamCorruptedException. If I send the array without the header I also get a StreamCorruptedException: "invalid stream header".
    If I reconstruct the object, by calling ObjectOutputStream.writeObject() and get it's byte array from ByteArrayOutputStream.toByteArray(), every time I have to fill the ByteBuffer, then it works.
    Here's the modified sending block, for the above example:
    } else if (key.isWritable()) {
                            SocketChannel client = (SocketChannel) key.channel();
                            if (buff.hasRemaining()) {
                                client.write(buff);
                            } else {
                                //* ---- added code ---------
                                baos.reset();
                                oos.writeObject("abcdefgh");
                                objectArr = baos.toByteArray();
                                buff.clear();
                                buff.put(objectArr);
                                buff.flip();
                        }   I really don't understand why I have to write the object in the object stream every time. I used ObjectOS and ByteArrayOS, to get the object byte array and then I thought I could forget about those streams and use this array to fill the ByteBuffer. What changes if I send the object through this process with every iteration (and how this harms speed - it's like sending everything twice)? If someone would explain this to me I would appreciate it much.

  • Java NIO locking and NTFS network resources

    Hi all - just ran into a really nasty situation and I was wondering if anyone else has hit it and might have some suggestions.
    Platform: JRE 1.4_02 on a Win XP machine
    The following test code locks a file, then copies it to another location using NIO.
    When I run it with source path on my local drives (C), it works fine. If I run it with source path on a network shared resource, it fails with an IOException with description 'Error performing inpage operation'.
    If I disable the lock immediately before the copy operation, it works fine.
    My conclusion is that there is something about the NIO locking implementation that prevents it from working properly with NTFS volumes on other hosts. Can this be right? I've found the following bug report:
    http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4774175
    but this seems like a huge problem that would prevent folks from using NIO in many, many applications. Maybe I'm wrong on something here...
    Anyway, here's the test code:
    import java.io.File;
    import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.RandomAccessFile;
    import java.nio.channels.FileChannel;
    import java.nio.channels.FileLock;
    * Created on May 28, 2004
    * (c) 2004 Trumpet, Inc.
    * @author kevin
    public class test {
         private void createFile(File f) throws IOException{
              FileOutputStream os = new FileOutputStream(f);
              for(int i = 0; i < 10; i++){
                   os.write(i);
              os.close();
         public test() {
              boolean testWithReleasingLockPriorToCopy = false;
              final File f1= new File("w:/temp/test2.lok");
              final File f2 = new File("w:/temp/test.lok");
              f1.delete();
              f2.delete();
              try {
                   createFile(f1);
                   RandomAccessFile raf1 = new RandomAccessFile(f1, "rw");
                   RandomAccessFile raf2 = new RandomAccessFile(f1, "rw");
                   FileChannel ch1 = raf1.getChannel();
                   FileChannel ch2 = raf2.getChannel();
                   FileLock flock1 = ch1.lock();
                  if (!f2.getParentFile().exists() && !f2.getParentFile().mkdirs())
                       throw new IOException("Unable to create directories for destination file '" + f2 + "'");
                  if (testWithReleasingLockPriorToCopy)
                       flock1.release();
                   ch1.transferTo(0, raf1.length(), ch2);
                   raf1.close();
                   raf2.close();
              } catch (Exception e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
         public static void main(String[] args) {
              test t = new test();
    }Does anyone have any pointers here? I need to be able to exclusively lock a file on a network drive (preventing any other applications from opening it), then make a copy of it. I can't use regular stream operations, because the lock prevents them from working properly (it appears that, once you grab a file lock using NIO, the only way your application can use the file is via the NIO operations - using stream operations fails...).
    Thanks in advance for any help!
    - Kevin

    i've run into the same problem recently, channels working fine for local file locking, but when you turn to the network, they fail to accurately handle locks.
    i ended up writing a jni utility to ship with my java application that locks files using native windows calls.
    my .c file ends up looking something like this:
    JNIEXPORT jint JNICALL Java_Mapper_NativeUtils_LockFile
    (JNIEnv *env, jobject obj, jstring filename)
    const char* ntvFilename = (*env)->GetStringUTFChars(env, filename, 0);
    int retVal = (int)CreateFile
    ntvFilename
    , GENERIC_WRITE
    , FILE_SHARE_READ
    , 0
    , OPEN_EXISTING
    , FILE_FLAG_SEQUENTIAL_SCAN
    , 0
    //add code to throw java exceptions based on retVal
    if (retVal == (int)INVALID_HANDLE_VALUE)
    return retVal;
    (*env)->ReleaseStringUTFChars(env, filename, ntvFilename);
    return retVal;
    JNIEXPORT jboolean JNICALL Java_Mapper_NativeUtils_UnlockFile
    (JNIEnv *env, jobject obj, jint handle)
         CloseHandle((void *)handle);
    return 1;
    it's a little shy on the error checking side, but it provides support for network file locking that java seems to lack.

  • NIO SocketChannel truncating write from MappedByteBuffer

    Hello!
    I'm running SDK build 1.4.1_01-b01 on Win2K (SP3), but I can also duplicate this on Linux (2.4 kernel).
    I'm writing a simple file server, and it uses the following code:FileInputStream fis = new FileInputStream(file);
    FileChannel fc = fis.getChannel();
    MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
    sc.write(buffer);
    sc.close()However applications that download (not just Java applications) do not receive the entire file. The server reports sending all of the bytes (sc.write() returns the value from fc.size()) but it is not all received byt the client downloading (I'm using wget on a Linux box).
    NIO has no way to flush, so... ok this is where I'm lost. Am I doing this all wrong?
    I even triedsc.socket().getOutputStream().flush();to no avail.
    Another similar example of this problem is the code from this article at JavaWorld:
    http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin.html
    The zip file contains only one class file that runs, except serving up say a 300kB Jar file does not work.

    Firstly thankyou very much for your time so far...
    I hope I'm not tripping over the protocol, I have implemented a simple HTTP server.
    The important section of code (very cut down - no log messages and less Exception handling) is:public class HttpGetHandler extends Thread {
        private SocketChannel sc;
        private File file;
        public HttpGetHandler_1(SocketChannel pSocketChannel, File pFile) {
            super("HttpGetHandler");
            this.sc = pSocketChannel;
            this.file = pFile;
            start();
        public void run() {
            try {
                // Open the file and then get a channel from the stream
                FileInputStream fis = new FileInputStream(file);
                FileChannel fc = fis.getChannel();
                // Get the file's size and then map it into memory
                long sz = (int) fc.size();
                // Create Header
                String header = new String(
                "HTTP/1.0 200 OK\r\n"
                + "Content-Length: " + sz + "\r\n"
                transmitBuffer(ByteBuffer.wrap(header.getBytes()));
                long position = 0;
                while (position < sz) {
                    MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_ONLY, position, sz - position);
                    transmitBuffer(buffer);
                    position += buffer.capacity();
            } catch (Exception e) {
            } finally {
                try {
                    // HACK
                    try {
                        Thread.currentThread().sleep(20000);
                    } catch (InterruptedException e) {
                        log.warn("InterruptedException", e);
                    sc.close();
                } catch (IOException e) {
        private void transmitBuffer(ByteBuffer pBuffer) throws IOException {
            while (pBuffer.hasRemaining()) {
                sc.write(pBuffer);
    }

  • Java.nio.channels.Pipe?

    Someone explain what java.nio.channels.Pipe should be uses for, and how to use it?

    You can use this class to transfer the content of a channel from one thread to another thread.
    The writing thread blocks when the pipe is full.
    package com.desoft.pipetest;
    import java.io.*;
    import java.nio.*;
    import java.nio.channels.*;
    public class PipeTest {
    public static void main (String args[])
    try
    FileInputStream fis = new FileInputStream(args[0]);
    FileChannel fc = fis.getChannel();
    Pipe p = Pipe.open();
    PipeReader pr = new PipeReader( p );
    Thread t = new Thread( pr );
    t.start();
    fc.transferTo(0, fc.size(), p.sink() );
    catch( IOException ioe )
    ioe.printStackTrace();
    * Read from a Pipe and write Content to System.out
    static class PipeReader implements Runnable
    Pipe p;
    public PipeReader( Pipe p )
    this.p = p;
    public void run()
    try
    ByteBuffer buffer = ByteBuffer.allocate( 10 );
    int len = 0;
    while( (len=p.source().read( buffer )) > 0 )
    buffer.rewind();
    for( int i = 0; i < len; i++ )
    System.out.print( (char)buffer.get());
    buffer.rewind();
    catch( IOException ioe )
    ioe.printStackTrace();

  • Socket disconnection event not being reveived java.nio

    Hi All
    My question is as below
    i am using java.nio package + win 2K + jdk1.4.1_02
    I have a Server accepting socket connection and is configured
    in Nonblocking mode.
    -The server receives (selector) events (accept event)
    when a client requests for a connection .
    -The server is getting read and write events when
    client wants to read and write
    -The server gets a read event when the client disconnects
    My only problem is that the Server is not getting any events
    when the client disconnect due to network break down
    for EX when the network connection breaks the client disconnects
    but the server selector is not getting any events
    I am storing the client Socket objects in a Hash Table and
    if i execute the .isConnected() method it returns true
    even though the the client is down
    The only work around is to try to read and write on the socket
    i get an IO exception and am able to make out that the
    client is disconnected
    But this is not desirable for my client
    as client modification to give any kind of echo is not possible and
    a read /write event will cause problem.
    Can any one tell how to detect client side disconnection
    with out Read and Write on the client socket
    I get an socket Exception when the socket is in Blocking IO and is blocked on read/ write but I am facing this problem in NonBlockingIO
    Regards
    Avinash

    int ct = read.selectNow();
    if (ct > 0)
    Set readyKeys = read.selectedKeys();
    Iterator i = readyKeys.iterator();
    while (i.hasNext())
    SelectionKey key = (SelectionKey) i.next();
    i.remove();
    if (key.isReadable())
    SelectableChannel nextReady = (SelectableChannel) key.channel();
    SocketChannel sc = (SocketChannel) key.channel();
    int rd = sc.read(buffer);
    // Link is dead
    if (rd == -1)
    key.cancel();
    key.attach(null);
    nextReady.close();
    continue;
    // Process your data
    catch (Exception e)
    e.printStackTrace();

  • Java System Copy Error

    Hi all. I am trying System Copy.
    During the Database Load I became the following Error
    "An error occurred while processing service SAP NetWeaver'04 Support Release1> Java System> MS SQL Server> Migration - Target System Installation."
    jload.log is:
    info: trying to create table IMS_SYNCINXVIEW
    com.sap.inst.jload.Jload dbImport
    info: table IMS_SYNCINXVIEW created
    com.sap.inst.jload.Jload dbImport
    warning: DB Error during import of IMS_SYNCINXVIEW
    com.sap.inst.jload.Jload printSQLException
    warning: Message: The SQL statement "INSERT INTO "IMS_SYNCINXVIEW" ("ACTIVITYID","RESOURCEID","DOCUMENTTYPE","FORMATVERSION") VALUES (?,?,?,?)" contains the semantics error[s]: table "IMS_SYNCINXVIEW" unknown
    com.sap.inst.jload.Jload printSQLException
    warning: SQLState: SAP06
    com.sap.inst.jload.Jload printSQLException
    warning: ErrorCode: 1001123
    com.sap.inst.jload.Jload dbImport
    info: trying to create table J2EE_CONFIG
    com.sap.inst.jload.Jload logStackTrace
    warning: java.nio.BufferUnderflowException
         at java.nio.Buffer.nextGetIndex(Buffer.java:404)
         at java.nio.HeapByteBuffer.getChar(HeapByteBuffer.java:234)
         at com.sap.inst.jload.io.DataFileEntry.<init>(DataFileEntry.java:52)
         at com.sap.inst.jload.io.DataFile.getNextEntry(DataFile.java:354)
         at com.sap.inst.jload.io.DataFile.findDataEntry(DataFile.java:397)
         at com.sap.inst.jload.db.DBTable.create(DBTable.java:77)
         at com.sap.inst.jload.Jload.dbImport(Jload.java:278)
         at com.sap.inst.jload.Jload.executeJob(Jload.java:397)
         at com.sap.inst.jload.Jload.main(Jload.java:621)
    com.sap.inst.jload.db.DBConnection disconnect
    info: disconnected

    Hi,
    I have also faced the same error during system copy, the tables IMS_SYNCINXVIEW, PVC_ACTVERSVIEW, PVC_OBJVERSVIEW which are related to Development Infrastructure. These are bad tables and hence it has to be removed.
    I found a file called negativTableListForJload.xml in C:\Program File
    sapinst_instdir\NW04S\LM\COPY\MSS\SYSTEM\CENTRAL\AS-JAVA\install\sltools\
    The import could be continued after removing the line
         <object name="IMS_SYNCINXVIEW" action="insert"/>
    (and of course the corresponding entries for all the other views) from
    the file IMPORT.XML
    So the steps u have to perform are
    Please cancel the Installation by pressing the cancel button and then stop the sapinst and edit these files and again continue the old installation.
    1) go to C:\Program File
    sapinst_instdir\NW04S\LM\COPY\MSS\SYSTEM\CENTRAL\AS-JAVA
    EDIT the IMPORT.XML i.e. delete the line
    <object name="IMS_SYNCINXVIEW" action="insert"/>
    2) now again got to C:\Program File
    sapinst_instdir\NW04S\LM\COPY\MSS\SYSTEM\CENTRAL\AS-JAVA\install\sltools\
    edit the negativTableListForJload.xml file. i.e. delete the lines which has the entry for these tables.
    3) Restart the installation. Donot retry.
    Reward point if u feel so.
    cheers
    Naveen.H

  • Using ByteBuffer from java.nio package

    Hi,
    I have a java.nio.ByteBuffer object that is returned from the C++ code, created using NewDirectByteBuffer. I would like to use this ByteBuffer object in my java code to create a WritableRaster object. I would like to avoid an array copy here as the data may be huge.
    Could someone please let me know if there is a solution to this?
    Thanks in advance for any help.

    Warning: I know almost nothing about the java.awt.image package - so please take what Im going to suggest as the throw away, off the top of my head random rambling that it is......
    Could you implement a custom DataBuffer which sits on top of a NIO ByteBuffer? Already, custom DataBuffers provide access for certain data types (e.g. theres a DataBufferByte, DataBufferDouble which wrap arrays) - so I guess you could write a NIODataBufferByte - or what ever - which sits on top of a ByteBuffer.
    Im not sure how this would tie in with the SampleModel though (again, I dont know anything about this area).
    Hopefully someone who knows this stuff will come across this thread and actually give you some decent advice :o)
    ~D

Maybe you are looking for

  • Photoshop CC 2014   Bridge CC: automated tasks missing

    I Have downloaded the new Photoshop CC 2014 and updated to Bridge CC. I am no longer able to run automated tasks from Bridge in Photoshop because the "photoshop" submenu is no longer available under tools- unistalling en reinstalling brings no avail.

  • Idvd image quality problems??

    Will the length of video on a dvd created with idvd affect the quality of the image? I have just created a dvd which is pretty packed 3.7 GB are used on the dvd. Most of the video looks great. However some sections later in the movie (which when shot

  • This device cannot start. (Code 10) Intel (R) 82566MM

    Ok guys I hope someone can help me with this annoying issue. Just today I clicked "undock Computer" and had to reboot becaues of some funky error message. When the machine came back on the LAN connection would no longer connect. Now under the status

  • Service Contracts API

    Hi Experts, I came across the api oks_contracts_pub which can be used to create contract headers,lines and sublines.My requirement is to update the start and end date of the headers ,lines and sublines after the contract is created. Can this api be u

  • Employee with change rights to all SC created in his org unit

    Hello, running ECS SRM 50 We need the possibillity to let one employee have the right to look at and change all shopping carts created within the organisational unity that he belongs to. He should not be able to approve them though. How can that be d