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

Similar Messages

  • Package java.nio package does not exists

    I am trying to move some steps in java environment.
    I am using a Windows98 O.S.
    I downloaded jdk1.3 for Windows from sun site and installed it in c:\jdk1.3.1_02
    I have set path variable as .....;c:\jdk1.3.1_02\bin
    I am trying to compile a java source including java.nio package.
    What I do is:
    javac example.java
    What I get is:
    package java.nio does not exists
    I saw a lot of documentation about how to use java.nio but not how to link it.
    Any help I appreciate.

    Package java.nio is introduced with the version 1.4

  • File Locking using java.nio package

    I am trying to lock a file using FileChannel's lock method on a CIFS file system. My application is on windows and the CIFS is accessed using UNC format ( \\1.2.3.4\blah.. ). I get the following error
         java.io.IOException: The network request is not supported
         at sun.nio.ch.FileChannelImpl.lock0(Native Method)
         at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:750)
         at java.nio.channels.FileChannel.lock(FileChannel.java:865)
    From the same machine using the same UNC formatm, when I lock the file using windows C API, I can successfull lock.
    Anyone has any idea why JVM can not lock even using nio package. Shouldnt it use the same ( or similar ) API under the hood as its clear by the package name java.nio
    The C program I am using is
    #include <io.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <sys/locking.h>
    #include <share.h>
    #include <fcntl.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void main( int argc, char **argv )
    int fh,numread;
    char buffer[40];
    char filename[500];
    /* Quit if can't open file or system doesn't
    * support sharing.
    if ( argc > 1 )
              strcpy(filename,argv[1]);
    else
              strcpy(filename,"locking.c");
    fh = sopen(filename , O_RDWR, SHDENYNO, //_SH_DENYRW,
    SIREAD | SIWRITE );
    if( fh == -1 )
    exit( 1 );
    /* Lock some bytes and read them. Then unlock. */
    if( locking( fh, LKNBLCK, 30L ) != -1 )
    printf( "No one can change these bytes while I'm reading them\n" );
    numread = _read( fh, buffer, 30 );
    printf( "%d bytes read: %.30s\n", numread, buffer );
    lseek( fh, 0L, SEEK_SET );
         printf( "Press a key to unlock the file.....\n" );
         getchar();
         locking( fh, LKUNLCK, 30L );
    printf( "Now I'm done. Do what you will with them\n" );
    else
    perror( "Locking failed\n" );
    _close( fh );
    }

    It uses LockFile and LockFileEx. Please check in the MSDN documentation the peculiarities of such APIs.
    JNIEXPORT jint JNICALL
    Java_sun_nio_ch_FileChannelImpl_lock0(JNIEnv *env, jobject this, jobject fdo,
                                          jboolean block, jlong pos, jlong size,
                                          jboolean shared)
        jint fd = fdval(env, fdo);
        HANDLE h = (HANDLE)_get_osfhandle(fd);
        DWORD lowPos = (DWORD)pos;
        long highPos = (long)(pos >> 32);
        DWORD lowNumBytes = (DWORD)size;
        DWORD highNumBytes = (DWORD)(size >> 32);
        jint result = 0;
        if (onNT) {
            DWORD flags = 0;
            OVERLAPPED o;
            o.hEvent = 0;
            o.Offset = lowPos;
            o.OffsetHigh = highPos;
            if (block == JNI_FALSE) {
                flags |= LOCKFILE_FAIL_IMMEDIATELY;
            if (shared == JNI_FALSE) {
                flags |= LOCKFILE_EXCLUSIVE_LOCK;
            result = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, &o);
            if (result == 0) {
                int error = GetLastError();
                if (error != ERROR_LOCK_VIOLATION) {
                    JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
                    return sun_nio_ch_FileChannelImpl_NO_LOCK;
                if (flags & LOCKFILE_FAIL_IMMEDIATELY) {
                    return sun_nio_ch_FileChannelImpl_NO_LOCK;
                JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
                return sun_nio_ch_FileChannelImpl_NO_LOCK;
            return sun_nio_ch_FileChannelImpl_LOCKED;
        } else {
            for(;;) {
                if (size > 0x7fffffff) {
                    size = 0x7fffffff;
                lowNumBytes = (DWORD)size;
                highNumBytes = 0;
                result = LockFile(h, lowPos, highPos, lowNumBytes, highNumBytes);
                if (result != 0) {
                    if (shared == JNI_TRUE) {
                        return sun_nio_ch_FileChannelImpl_RET_EX_LOCK;
                    } else {
                        return sun_nio_ch_FileChannelImpl_LOCKED;
                } else {
                    int error = GetLastError();
                    if (error != ERROR_LOCK_VIOLATION) {
                        JNU_ThrowIOExceptionWithLastError(env, "Lock failed");
                        return sun_nio_ch_FileChannelImpl_NO_LOCK;
                    if (block == JNI_FALSE) {
                        return sun_nio_ch_FileChannelImpl_NO_LOCK;
                Sleep(100);
        return sun_nio_ch_FileChannelImpl_NO_LOCK;
    }

  • Java.nio package Runtime error java.lang.UnsupportedClassVersionError.

    Hi
    I am using nio package and create a java program for file locking (FileLocking.java).
    Here is the sample
    try {
    file = new File("C:/acc.txt");
    channel = new RandomAccessFile(file, "rw").getChannel();
         lock = channel.lock(0, Long.MAX_VALUE, true);
    try {
              lock = channel.tryLock(0, Long.MAX_VALUE, true);
    catch (OverlappingFileLockException e) {
    return true;
    using wsad 5.1 and jdk1.4 i compiled this program.
    While executing i got the following runtime error..
    java.lang.UnsupportedClassVersionError: FileLocking (Unsupported major.minor version 48.0)
         at java.lang.ClassLoader.defineClass0(Native Method)
         at java.lang.ClassLoader.defineClass(ClassLoader.java:703)
         at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:133)
         at java.net.URLClassLoader.defineClass(URLClassLoader.java:319)
         at java.net.URLClassLoader.access$400(URLClassLoader.java:92)
         at java.net.URLClassLoader$ClassFinder.run(URLClassLoader.java:677)
         at java.security.AccessController.doPrivileged(Native Method)
         at java.net.URLClassLoader.findClass(URLClassLoader.java:238)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:516)
         at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:441)
         at java.lang.ClassLoader.loadClass(ClassLoader.java:448)
    Exception in thread "main"
    Even if i try to recompile it in command prompt and run, i got the same error.
    please suggest me how can i overcome this problem.

    UnsupportedClassVersionError means that you are trying to execute a class for a newer version of the JVM on an older version of the JVM.
    Version 48.0 is for Java 1.4, so you have compiled your class with JDK 1.4.
    The computer you are trying to run the class on, has an older version of Java than 1.4 - check it!
    Try recompiling your source files with the "-target" switch, for example if you're running on Java 1.3, try compiling with:
    javac -target 1.3 ... FileLocking.java

  • Java.nio package

    Is there a good tutorial somewhere which explain in depth the new I/O package in JDK 1.4 java.nio?

    And there is the JavaWorld article at:
    http://www.javaworld.com/javaworld/jw-09-2001/jw-0907-merlin.html
    but the example code they give is a little broken, and
    the article is also a little confusing. But it can help a little.
    I have also started some threads on these forums about the bugs in that article.

  • Using XPath from Java

    I've heard that you can use XPath from within Java instead of having to use it within XSLT, but I'm not sure what the syntax is?
    Does anyone know?
    Thanks,
    Oodi

    import org.apache.xerces.parsers.DOMParser;
    import org.apache.xpath.XPathAPI;
    DOMParser parser = new DOMParser();
    parser.parse(inputFile);
    doc = parser.getDocument();
    /* Search using XPATH */
    String xpath = "/XpathToSearch";
    NodeIterator nl = XPathAPI.selectNodeIterator(doc, xpath);
    HTH,
    Joe

  • How can i use twain from java servlet?

    dear all
    iam a web developer ,iam haviving now a task to search in point pf scanning image through web (Intranet) using java
    can any one tell where can i find resources how to deal with Twain using java (On web specially not from a desktop application)
    i hope u can help me
    Thanks in advance
    Yours,
    Amr
    Senior Java Web developer

    Hi,
    You can try a package named: JTwain, which is available at http://asprise.com/product/jtwain.
    JTwain supports all kinds of digital cameras and scanners. You can use Java to access, contorl digital cameras and scanners, and of course, to acquire images with flexible settings.
    The developers' guide is available @ http://asprise.com/product/jtwain/devGuide.php
    In the simplest case, one line of Java code can solve your problem.
    Good luck!

  • Using JNDI from Java Stored Procedures

    Hi,
    we want to call external services (mostly via middle tier/J2EE) from within the database (9i Rel. 2) using Java Stored Procedures and JNDI.
    Does anybody have some hints/samples how to do this? Will we have to use oc4jclient.jar? If yes, how? Where can I find some more detailed documentation?
    Lot's of questions...
    Thank
    Matthias

    Uh, not JNI but JNDI you asked. And use of JNI should be generally discouraged unless there is absolutely no other way (like co-located CORBA code for decoupling+speed). Can you direct me to a HOW-TO Oracle DB JVM configuration page? I want to know how to configure the internal DB JVM in a hurry.
    Thank you,
    Bryan

  • Connecting to AW using AWConnection from java

    Hi all,
    I have some java code which performs some AW manipulation based on relational tables, the code works perfectly both inside the database and externally.
    The problem I have is that I don't want to have to pass the username, password, and connectstring into the java procedure. I want to take advantage of the "kprb" type connection, i.e. I want to be able to use the defaultConnection method of the Oracle driver like I would with jdbc: the session has already been connected by sqlplus
    I can't work work out if this is possible via the AWConnection method, I guess it must be using a loopback type connection based on the tnsnames.
    Anyone know if it can be done?
    Cheers,
    Mark...

    Hi Mark,
    The AWXML api has a mode which does exactly what you want, you should create an Interaction object which contains a set of actions you want to perform. This object can then be serialized into xml by calling the writeToXML method on it. At this point, you can use the returned string to create a clob which is then passed to a pl/sql procedure called sys.interactionexecute. This procedure takes the xml as a clob and executes it in the internal jvm using the connection information from the envoker of the pl/sql procedure.

  • Using DCs from Java DC

    I need to use tc/wd/webdynpro (default) DC in a Java DC. I add it in Used DCs with Build Time (and I also try with build, design, run time...), compile and deploy successfull but when I run web dynpro DC that use Java DC (deployed with J2EE DC), the class IWDNodeNotificationListener is not found.
    ¿What option I need to use tc/wd/webdynpro DC in runtime?

    Hi Sebastian,
                          I guess this is the problem with required class or package not defined.  check this link once.
    http://www.petsounds.org/sapjavadocs/webdynpro/com/sap/tc/webdynpro/progmodel/api/IWDNodeNotificationListener.html
    Regards,
    Anil.

  • Using COM from java

    hi all,
    I'm trying to find a way to call functions from a C++ COM object (.tlb).
    Since I don't have a clue about C++ I thought about using an API or Tool that will help me to generate the appropriate wrappers and stubs to use with java.
    Does someone have any idea of an API or Tool which is suitable for the above scenario?
    many thanks in advance..........

    See
    http://simtel.net/product.php[id]60701[sekid]0[SiteID]simtel.net

  • JNI : Unsatisfied Link Error using C++ from Java

    Am using JNI to call a C Function which in turn creates a new C++ object and calls a method on it.
    When I run the java program that calls this native method, I get a UnsatisfiedLinkError : No <lib> in java.library.path.
    If I change the C function to do a simple printf instead of creating a new object , it works fine.
    I am printng out the java.library.path before calling the loadLibrary method, the path is correct.
    Am using Java 1.2.2 and compiling with gcc 2.7 on solaris 2.6 (Sun OS 5.6)
    Any help would be appreciated. I have seen some other folks having similar problems but haven't seen any replies that seem to solve the problem.

    Thanks for the ldd suggestion :
    This is the output from ldd
    ldd -sir liba.so
    find library=./liba.so; required by /usr/lib/lddstub
    find library=libe.so; required by ./liba.so
    search path=/user/ajax/jni (LD_LIBRARY_PATH)
    trying path=/user/ajax/jni/libe.so
    libe.so => /user/ajax/jni/libe.so
    symbol not found: strcpy (/user/ajax/jni/libe.so)
    symbol not found: strcpy (/user/ajax/jni/libe.so)
    symbol not found: printf (/user/ajax/jni/libe.so)
    symbol not found: printf (/user/ajax/jni/libe.so)
    symbol not found: __builtin_new (/user/ajax/jni/libe.so)
    symbol not found: printf (/user/ajax/jni/libe.so)
    init library=/user/ajax/jni/libe.so
    init library=./liba.so
    libe.so is in the LD_LIBRARY_PATH
    The 'man' pages for ldd say this :
    Using the -d or -r option with shared objects can give misleading results. ldd does a "worst case" analysis of the shared objects. However, in practice some or all of the symbols reported as unresolved can be resolved by the executable file referencing the shared object.
    Most of them seem ok, but I am wondering about "__builtin_new", anyone know what shared lib that's supposed to be in ?

  • Example code for Trigering a workflow using WAPI from JAVA based tool

    Hi Experts,
    I am the newest guy in SAP workFlow and BAPI world. I need to trigger a workflow defined in WebFlow engine from a Java client. I know i can use JCo and to use WAPI to get workflow information but i am not sure how it works. Can you give me some example code to trigger one workflow defined in WebFlow using WAPI? If there is any alternative i am interested to know that as well.
    Thanks in advance.
    Regards,
    Riyadh

    Use Function Module SWE_EVENT_CReate top trigger event that is linked with a Workflow.
    <b>Please reward points if useful</b>
    INCLUDE <cntn01> .
      DATA:i_emp_details TYPE STANDARD TABLE OF p0001,  "Employee Details
           wa_request    TYPE p0001,                    "Workarea for Employee details
           v_country_grp TYPE molga,                    "Country SubGrouping
           v_object_key  TYPE sweinstcou-objkey.        "Key for the buisness object ZWOBUSTRIP
      CONSTANTS: c_bo_trip     TYPE swo_objtyp VALUE 'ZWOBUSTRIP',
                 c_event_trip  TYPE swo_event  VALUE 'TripCreate',
                 c_infy_type_1 TYPE infty      VALUE '0001'.
    Event Container declaration
      swc_container i_event_cont.
      swc_create_container i_event_cont.
    Reading the INFO TYPE 0001 to obtain the
    Employee details
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
          pernr           = i_emp_number
          infty           = c_infy_type_1
          begda           = sy-datum
          endda           = sy-datum
        TABLES
          infty_tab       = i_emp_details
        EXCEPTIONS
          infty_not_found = 1
          OTHERS          = 2.
    SY-SUBRC check is not required as the error
    handelling will be done by WorkFlow rule
    resolution.
      CLEAR wa_request.
      READ TABLE i_emp_details INTO wa_request INDEX 1.
      IF sy-subrc = 0.
      Retrieving the Country SubGrouping for the employee
        SELECT SINGLE molga
          FROM t001p
          INTO v_country_grp
         WHERE werks = wa_request-werks
           AND btrtl = wa_request-persk.
      ENDIF.
    Sending the relevant data to event container
      swc_set_element i_event_cont 'EmpId'     i_emp_number.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
      swc_set_element i_event_cont 'PersonnelArea'    wa_request-werks.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
      swc_set_element i_event_cont 'CountryGrouping' v_country_grp.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
      swc_set_element i_event_cont 'EmpSubGrp'       wa_request-persk.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
      swc_set_element i_event_cont 'EmpTripId'       i_emp_trip.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
    Raising the event to trigger the workflow
      v_object_key = i_emp_number.
      CALL FUNCTION 'SWE_EVENT_CREATE'
        EXPORTING
          objtype           = c_bo_trip
          objkey            = v_object_key
          event             = c_event_trip
        TABLES
          event_container   = i_event_cont
        EXCEPTIONS
          objtype_not_found = 1
          OTHERS            = 2.
      IF sy-subrc <> 0.
    No Processing needed.
      ENDIF.
      COMMIT WORK.
    ENDFUNCTION.
    Thanks
    Arghadip

  • Download java.nio package source code

    Where can I find NIO source code? Any Java 5 version would be great.
    This code is open source.
    thanks!

    Sun's NIO source can be downloaded from the JDK d/l page.
    This IS NOT open source code, you have to agree to the license terms.
    If you want open source code, check out the OpenJDK project at java.net

  • Using Perl From Java!

    Hi there, i have an assignment for university, part of it is to send data to a perl script through a Java applet. My perl script works, as i have tested it with a HTML form, however when i try it with java, i get nothing, nothing, no errors or warnings. Im using JBuilder6.
    I am convinced that there is a problem with my code and a connection is not being opened, my lecturer cant see what the problem is (im not too impressed!) so i come to you.
    All the perl does is create a file called test.txt and print within it the name, email..etc from the applet.
    Thanks in Advance, Dave Williams.
    JAVA:
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

    Hi All heres the code with the propper tags i think, as for smorgasbords comment, I realise the security issue with java, but my lecturer seems to think its a good idea. Now the java applet opens a stream to my perl script and sends it parameters which the perl script uses to create the file. So java isnt making the file on any computer, perl is creating it on the server (EasyPHP actually). The example code given by my lecturer does actually work however for reasons which neither myself or the lecturer cannot see, it just doesnt create the file (or even open the perl script for that matter, as i used a file monitor to check if the 'diag.pl' file was accessed). I hope ive cleared up any questions.
    Thanks
    Dave
    void btnSendPosting_actionPerformed(ActionEvent e) { //Send Posting Event
    name = txtName.getText();
    email = txtEmail.getText();
    message = txtareaText.getText();
    path = txtFilePath.getText();
    String url = "http://localhost/cgi-bin/diag.pl";
    System.out.println("Url entered");
    try
    theURL = new URL(url);
    System.out.println("Url prepaired");
    catch (MalformedURLException f)
    System.out.println("Bad URL: " + theURL);
    try
    System.out.println("Beggining Connection...");
    URLConnection connection = theURL.openConnection();
    connection.setDoOutput(true);
    PrintWriter out = new PrintWriter(connection.getOutputStream());
    out.print("txtName="+name +"&txtEmail="+ email +"&txtMessage="+ message +"&txtPath="+path);
    out.close();
    System.out.println("End of Connection");
    catch (IOException f)
    System.out.println("Error Opening Connection");
    } //Send Posting Close bracket

Maybe you are looking for

  • How do I remove PSE 7 after installing PSE 8?

    After successfully installing PSE 8, I tried to remove PSE 7 from my Dell PC computer. However, PSE 7's icon is not displayed in Vista's "uninstall or change" window (the place where Vista shows all the installed programs). Only PSE 8's icon appears.

  • HU - Repack with WM

    Hi Gurus, I would like to know if this is mandatory to send the material that is needed to repack to storage type 923 - PACK.BIN. For example: I have a pallet (SU) with 10 boxes on it (HU) stored in a storage type with putaway strategy, capacity chec

  • Incompatible types in simple odbc statements

    this is my simple code import java.sql.*; public class QueryApp {      public static void main(String a[]){           try{                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");                Connection con;                con=DriverManager.g

  • Catching events on Desktop , without using any AWT or Swing components.

    How can I catch events(for eg: mouse clicks) on the Desktop? I do not want to use any AWT or Swing components in my application. Also, i want to get events even some other java/non-java application windows are visible on desktop, as long as my applic

  • Rendering Freeze in Premiere CS4

    I had a DV 24P project go into what I call "rendering freeze" - it opens up the render box, but then does nothing. It will simply sit there for hours if I let it, but I can escape out of it at any time. The project was a CS3 import that is 95% done,