Asynchronous read & write by using Asynchronous api provided in nio-java 7

HI,
I am trying to write a small program to implement **asynchronous read & write by using Asynchronous api provided in nio in java 1.7** in windows machine.
i tried the following code to write a small string to a file asynchronously.file is getting created but the contents are not dispalying.
     static long startTime = System.currentTimeMillis();
     static long endTime;
     static long execTime;
     public static void main(String[] args) {
          String path = "C:\\AsynchWrite.txt";
          Path file = Paths.get(path);
          final AsynchronousFileChannel channel;
          long pos = 1;
          try {
               OpenOption[] options = { StandardOpenOption.CREATE,
                         StandardOpenOption.WRITE, StandardOpenOption.SYNC };
               channel = AsynchronousFileChannel.open(file, options);
               ByteBuffer buffer = ByteBuffer.allocate(1000);
               String writeThis = "Testing by writing a line";
               byte[] src = writeThis.getBytes();
               buffer.put(src);
               channel.write(buffer, pos, null,
                         new CompletionHandler<Integer, Object>() {
                              @Override
                              public void completed(Integer result, Object attachment) {
                                   System.out.println("completed successfully");
                                   System.out.println("start time :" + startTime);
                                   endTime = System.currentTimeMillis();
                                   System.out.println("end time : " + endTime);
                                   execTime = endTime - startTime;
                                   System.out.println("Execution Time :" + execTime);
                                   System.out.println("Execution Time(ms) :"
                                             + execTime);
                                   try {
                                        channel.force(true);
                                        channel.close();
                                   } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                              @Override
                              public void failed(Throwable exc, Object attachment) {
                                   // TODO Auto-generated method stub
                                   System.out.println("failed!!");
          } catch (IOException e) {
               // TODO Auto-generated catch block
               e.printStackTrace();
     }Please help me out
Thanks in advance,
Ravi

It looks like you are missing buffer.flip() after your put as otherwise the buffer position will be at 25 (not 0 as you expect).

Similar Messages

  • How to read inline feed using android api for odata

    Hi,
    Need help on reading inline feed using android api. BB and iOS supports inline but for android there is no api.
    Please suggest the workaround
    Regards,
    Satish

    This link is very useful:
    Knowledge Management and Collaboration (KMC)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/kmc/Knowledge%20Management%20and%20Collaboration%20Developers%20Guide.html
    Patricio.

  • How to use SEARCH-API provided by portal30 default schema

    I want information about the search api provided by the
    default portal30 schema.
    How can i use that for my specific requirement.
    i want to manipulate it's search limits
    is it possible ???
    Can i customize the specification provided in this api

    Hi,
    about the addDataSource using the Java API, for now you have to disable the security
    in order to add the data source using the MapViewer client API.
    You can do that editing the MapViewer config file:
    <mv_security enforce_sec_role="false" />
    Assuming that you have added your data source, and you have rendered some map,
    you can get the attribute information using the "identify" methods of the
    MapViewer client API.
    1) To identify one individual geometry:
    String [][] result = mapviewer.identify(dataSource,table_name,columns,
    geometry_column,srid, x, y);
    where: "columns" contains the table attribute names that
    you want to retrieve
         x,y represents the device coordinate.
    2) To identify geometries inside a rectangle:
    String [][]result = mapviewer.identify(dataSource,table_name,columns,
    geometry_column,srid, xlowleft,ylowleft,
    xupright,yupright,false);
    where the rectangle coordinates are defined by xlowleft,ylowleft,
    xuprigth, and yuprigth values in device unit.
    3) The resulted String array contains on the first row the attribute
    names, and on the remaining rows the attribute values for each geometry.
    int nlin = result.length; // return the number of lines
    int col = result[0].length; // number of columns
    To get the attribute names:
    // attribute names
    Object []tableattrs = new Object[ncol];
    for(int j=0;j<ncol;j++)
    tableattrs[j] = result[0][j];
    To get the attribute values:
    Object [][]tablevalues = new Object[nlin-1][];
    for(int lin=1;lin<nlin;lin++)
    tablevalues[lin-1] = new Object[ncol];
    for(int col=0;col<ncol;col++)
    tablevalues[lin-1][col] = result[lin][col];
    Regards.

  • Unable to read/write bytes using 9870 with cRio 9151

    Hi everyone,
    I'm currently having some problems trying to use 2 ports of module NI 9870. I'm unable to read bytes even if I try to send some datas (I always get a Timeout) and I'm also unable to write some datas( I can't see nothing on Hyperterminal).
    Please find enclosed a snapshot of my Fpga code.
    Regard,
    Nicolas Kaminski, Toulouse France
    Attachments:
    ReadBytes.jpg ‏93 KB
    WriteBytes.jpg ‏30 KB

    Hello,
    Can you give us some other details:
    Are you sure that you provide power to the 9870 module?
    Do you have tested your system with an example? (NI-987x Serial Loopback.lvproj)
    DO you get something through that loopback?
    Regards,
    Mathieu P. | Certified LabVIEW Associate Developer
    National Instruments France
    #adMrkt{text-align: center;font-size:11px; font-weight: bold;} #adMrkt a {text-decoration: none;} #adMrkt a:hover{font-size: 9px;} #adMrkt a span{display: none;} #adMrkt a:hover span{display: block;}
    Journées techniques : des fondamentaux aux dernières technologies pour la mesure et le contrôle/comm...

  • Reading Inactive objects using repo API

    Hi,
    Is there a way to read inactive objects that resides inside a package using XSJS repo APIs. Also, How do we delete such objects. I have written code that would do the same for active version of objects only. But, not sure how to perform the same for inactive objects. Little pointer in this direction would be great.
    Thanks in Advance,
    Vikas.

    The Repository XSJS APIs are not documented nor released for external usage. Please do not discuss SAP internal only APIs on the public forums.  As you are an SAP employee you should use the internal forums for such internal API questions. 
    I would add that even internally at SAP we aren't supposed to use the XSJS Repository APIs any longer.  Please convert your code to use the REST Repository APIs instead.

  • Read/write keywords using applescript and iMagine Photo

    Does anyone know if applescript & iMagine Photo are capable of reading/writing to the IPTC keywords?
    I can't seem to figure it out. I use
    {exif type:info, exif unicode:gImageInfoText}}
    to modify description ({exif type:info, exif unicode:gImageInfoText}) field of the IPTC data but can't understand how to write to the keywords field.
    Does anyone know to simply read the keywords form the IPTC data?
    Thanks.
    Pedro

    You could install [ExifTool|http://www.sno.phy.queensu.ca/~phil/exiftool>, and then use “do shell script” commands such as in the following examples:
    *do shell script "exiftool -keywords=AppleScript -keywords=\"iMagine Photo\" -keywords=IPTC ~/Desktop/myPicture.jpg"*
    --> " 1 image files updated"
    *do shell script "exiftool -keywords ~/Desktop/myPicture.jpg"*
    --> "Keywords : AppleScript, iMagine Photo, IPTC"
    Message was edited by: Pierre L.

  • Read/Write ints using 2bytes

    Hi. I was wondering if anyone can help me read and write one interger using two bytes. I have an interger between 500-800 that I need to write. Normally I would use...
    OUT.writeByte(int)
    But as 500 is above one byte (256) I was wondering how to write this, and then later read it back.
    As since one int would be spread over two bytes, I have no idea how to read it, normally I would use
    IN.readByte()
    And I have no idea how to do this. Can anyone help me please?

    You were told how to do this using individual bytes in your other thread here:
    http://forum.java.sun.com/thread.jspa?threadID=576927&tstart=0
    If you don't know how to write the code and are not willing to use the Java Tutorial to learn how to do it, then write it as a short, which is 2 bytes.
    (You write the code, we comment on the problems, not the other way 'round)

  • Help:NoSuchMethodError thrown when reading excel sheet  using jxl API

    I'm trying to read data from an Excel-2003 sheet using this code:
    15. File file = new File("EmpDetails.xls");
    16. jxl.Workbook workbook = jxl.Workbook.getWorkbook(file);                              
    17. jxl.Sheet sheet = workbook.getSheet(0);
    18. jxl.Cell cell1 = sheet.getCell(0,0);I'm getting this java.lang.NoSuchMethodError: common.Assert.verify(Z)V. The StackTrace is given below:
    Exception in thread "main" java.lang.NoSuchMethodError: common.Assert.verify(Z)V
         at jxl.read.biff.SSTRecord.getString(SSTRecord.java:417)
         at jxl.read.biff.LabelSSTRecord.<init>(LabelSSTRecord.java:56)
         at jxl.read.biff.SheetReader.read(SheetReader.java:306)
         at jxl.read.biff.SheetImpl.readSheet(SheetImpl.java:611)
         at jxl.read.biff.WorkbookParser.getSheet(WorkbookParser.java:204)
         at com.scjp.IO.ExcelJXL.main(ExcelJXL.java:17)Please help.

    Thanks a lot for the reply.
    I had both jxl.jar and xlrd.jar in the classpath and xlrd.jar was loaded before jxl.jar.
    There is a conflicting common.Assert.class file in xlrd.jar and there is no verify method in it.
    That was creating the problem. I loaded the jxl.jar file before the xlrd.jar and it is working fine.
    Thanks a lot for the help!!! :)

  • Use OC4J jms provider in a java application

    Hi all,
    I'd like to send messages in a OC4J queue (declared in jms.xml) using a java application, is it possible?
    Thank in advice, Cesare
    I read messages by a servlet using this code:
    factory = (QueueConnectionFactory)new InitialContext().lookup("jms/myQueueConnectionFactory");
    queue = (Queue) new InitialContext().lookup("jms/myQueue");
    connection = factory.createQueueConnection();
    connection.start();
    QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueReceiver receiver = queueSession.createReceiver(queue);
    Message message = receiver.receive();

    hi
    if you wish to know how to send and recieve messages from a queue then there is a sample application available at the following link.
    http://otn.oracle.com/sample_code/tech/java/oc4j/samplesPage.html
    try the ch19 sample.
    hope this helps
    regards
    shrinivas

  • Set Security Question & Answer using UME API in Web dynpro Java

    Hi Experts,
    I;ve developed a Web Dynpro java application to create a user in UME.
    I am able to set all the user account related attributes but I am not able to set the security question and answer as I do not see any attribute for the same.
    Can anyone please suggest how to set the Security question and answer in UME?
    This is required so that if the user wishes to reset his password / forgets password, we can ask him the security question which he selected at the time of registration.
    Please let me know if it can be achieved at the code level and whether UME API supports security question and answer or any such attribute.
    Also, if no such attribute is present by default in UME at the moment; can we create/configure some custom attributes in UME and store the security question and answer into those attributes. This would serve our purpose.
    Kindly assist.
    Regards,
    Anurag

    Hi,
    Thanks a lot for the reply!!!
    I have one doubt here:
    You've mentioned the below code to fetch the security questions in your reply:
    IUser user = WDClientUser.getCurrentUser().getSAPUser();
    String CUSTOMER_NAMESPACE = "com.sap.security.core.usermanagement";
    String attmotname [] = user.getAttribute(CUSTOMER_NAMESPACE,"MotherName");
    String attlucknum [] = user.getAttribute(CUSTOMER_NAMESPACE,"LuckyNumber");
    String attmobnum [] = user.getAttribute(CUSTOMER_NAMESPACE,"MobileNumber");.
    But this would be only applicable when the user has already logged on to the portal as it uses "WDClientUser.getCurrentUser().getSAPUser();" code.
    On the contrary, I want the security questions and answer to be accessed even when the user is not logged on to Portal so that based on the question & answer, the user can reset his password.
    Please suggest, how can we achieve this and where and how to set the custom attributes for the same?
    Do we have to set the Publicly Viewable Custom Attributes present at location you mentioned in your reply?
    Also, if yes; please let me know how to set the custom attributes?
    Thanks & Regards,
    Anurag

  • Async read/write

    Hi all,
    I am developing a device driver for a custom PCI card on 64 bit Sparc
    Solaris 8 which is going to replace another card. We already have
    applications running, so I'm supposed to give the same interface as the
    original one.
    The application with the original driver/card makes asynchronous
    reads/writes as follows:
    - open(device, O_RDWR | O_NONBLOCK)
    - call write
    - for (;;) {
    call ioctl to get device status
    break on completion or error.
    - call write second time (same buffer, same size)
    So, in the driver, I should implement async writes in the 'write'
    entry, not 'awrite'.
    I was thinking of creating an aio_req structure and calling aphysio
    inside 'write', but this is not documented. Another problem in this
    approach is the second call to 'write' in the application.
    So my questions are:
    1) How should I implement this? Create a thread and provide async
    functionality inside this thread? But this doesn't make much sense to
    me because there's already an async functionality provided by Solaris.
    2) What could the purpose of the second 'write' call be in the user app.
    Thanks in advance

    All has been checked, and rechecked.
    We now have a very strange situation:
    We testen failover by manually turning of one LPAR at a time.
    After this reboot, the Async I/O error seem to have gone.
    That is, they haven't appeared now for two days
    Why they occurred and why they don't occur anymore is not found/explained
    There I'll close this thread.

  • Best practice for development using REST API - OData

    Hi All, I am new to REST. I am a developer who works mostly in server-side code using Visual Studio. Now that Microsoft is advocating to write code using REST API instead of server-side code or client side object model, I am trying to use REST API.
    I googled and most of the example shows to write a code and put it on Content Editor/Script Editor. How to organize code and deploy to the staging/production in this scenario? Is there any Best Practice or example around this?
    Regards,
    Khushi

    If you are writing code in aspx or cs it does not mean that you need to deploy it in the SharePoint server, it could be any other application running from your remote server. What I mean it you can use C# & Rest API to connect to SharePoint server.
    REST API in SharePoint 2013 provides the developers with a simple standardized method of retrieving information from SharePoint and it can be used from any technology that is capable of sending standard HTTP requests.
    Refer to the following blog that provide your more details about comparison of the major features of these programming choices/
    http://msdn.microsoft.com/en-us/library/jj164060.aspx#RESTODataA
    http://dlr2008.wordpress.com/2013/10/31/sharepoint-2013-rest-api-the-c-connection-part-1-using-system-net-http-httpclient/
    Hope this helps
    --Cheers

  • Read/write problem with Datasockets.

    Hi, I'm a newcomer to Labview, and I'm having a problem with Datasockets. When trying to create a 'Publish & Subscribe' socket between two machines it only works on one, the one whose dstp address is the local machine, the other being incapable of writing to this 'host' and displaying red LEDs, although it is reading from the host. Also I've only managed to set up these read/write connections using the right-click options, how is it done programatically? Any clarification on the issue (whether directly connected or not :-) would be appreciated. Many thanks,
    Tom

    Hi Lector!
    This is normal behavior for DataSocket. You want to run a DataSocket server on both machines. Although you can SUBSCRIBE to a DS server anywhere on the network, you can only publish to your local server. We do a LOT of Datasocket work here, and this has never been a problem. It's a real security bonus, as well.
    It's a good idea to split all your read and write functions. Although some front panel objects (knobs, particularly) can be controls and indicators simultaneaously, it's good practice, for a number of reasons, to NOT use both functions. I build "dummy" front panels for all my VI's which I distribute to all my colleagues who need to work with a remote instrument.
    You cannot really appreciate DataSocket, till you've tried to rem
    otely control something with PC Anywhere over a slow network! A bit of practice, and you'll wonder how you ever did anything without DataSocket. I'd be glad to work with you on any particulars. Good Luck!
    Eric
    Eric P. Nichols
    P.O. Box 56235
    North Pole, AK 99705

  • Read write permissions

    When I move a folder from an external hard drive to the internal hard drive on my laptop, all the files and folders become read only. It is very annoying to change hundreds of files to read/write for use with Word or Photoshop and other applications. Just changing folder permissions does not change the internal files. Is there a general solution to this problem?

    http://en.wikipedia.org/wiki/Filesystempermissions
    Files on a Web server are a lot different than "local" files. On your Mac you have a "User" account and only you have access (assuming you've set a password for log-in at that account).
    The files found on a server (MobileMe or any other) would be uploaded by "you" and access to those files is also password protected. If your password could be found anyone could modify or delete your files because the server wouldn't "know" it wasn't you that authorized those changes.
    This is a lot different than the Unix file system permissions used in OS X. Since you could have dozens of User accounts then each of those accounts could access the iWeb application. But they couldn't modify any file stored in an other User's "Home" folder (where the iWeb package file is kept).
    Apple servers could access your files stored or served from your iDisk. It's part of the terms of use agreement that you allowed when you signed up for the service. This is an entirely different version of file "permissions".
    I may not have explained this in the best fashion or skill. Others are free to chime in.

  • Error when creating record from portal into MDM using MDM API's

    Hi All,
    When trying to create a new record from Portal we are getting the below error. It is working fine till yesterday.
    We are using MDM API's from webdynpro java for creating.
    What could be the reason for this. Not sure whether this error is ocuring for all the users or for single user.
    "Exception: CommandException com.sap.mdm.commands.CommandException: com.sap.mdm.internal.protocol.manual.ServerException: Database command execution error. A SQL statement failed to execute. The actual error may have been written to a log file."
    Please help to resovle this.
    Thanks
    Satish

    Hello Satish
    Suppose your Portal was upgrated
    if it right -  search and deploy new mdm packages
    Regards
    Kanstantsin

Maybe you are looking for