File Channel Problem

I have written a small method, that converts file content to CharSequence. For some reason it maintains a lock on the file. After calling CharSequenceFromFile method I cannot delete the file.
Obviously there is something that I don't understand something about FileChannel. Any help will be appretiated, thanks for ur time.
import java.io.*;
import java.nio.*;
import java.util.*;
import java.util.regex.*;
import java.nio.channels.*;
import java.nio.charset.*;
public class RegExTest {
     public static void main (String args[])throws Exception {
          CharSequence charSequence = CharSequenceFromFile("f.txt");
          File f = new File("f.txt");
          System.out.println("del"+ f.delete()); //prints false
     public static CharSequence CharSequenceFromFile(String filename) throws IOException {
          FileInputStream fis = new FileInputStream(filename);
          FileChannel fc = fis.getChannel();
          ByteBuffer bbuf = fc.map(FileChannel.MapMode.READ_ONLY,0, (int)fc.size());
          CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf);
          fc.close();
          fis.close();
          return cbuf;
} PS: can it be a java bug?

The Java API v1.4.1 states the following about MappedByteBuffers :
'A mapped byte buffer and the file mapping that it represents remain valid until the buffer itself is garbage-collected.'
See the comments in code below...
import java.io.*;
import java.nio.*;
import java.util.*;
import java.util.regex.*;
import java.nio.channels.*;
import java.nio.charset.*;
public class RegExTest {
public static void main (String args[])throws
Exception {
CharSequence charSequence =
= CharSequenceFromFile("f.txt");
          File f = new File("f.txt");
System.out.println("del"+ f.delete()); //prints
s false
public static CharSequence
CharSequenceFromFile(String filename) throws
IOException {
FileInputStream fis = new
w FileInputStream(filename);
          FileChannel fc = fis.getChannel();
ByteBuffer bbuf =
= fc.map(FileChannel.MapMode.READ_ONLY,0,
(int)fc.size());
CharBuffer cbuf =
=
Charset.forName("8859_1").newDecoder().decode(bbuf);
          fc.close();
          fis.close();// add these lines below it will start working
          bbuf.clear();
          bbuf = null;
          System.gc();
// till here
          return cbuf;
PS: can it be a java bug?
NOT A BUG

Similar Messages

  • Problem in File Channel

    Hi,
    I have a scenario whice is split in two parts (to be precise two saperate scenarios execute).
    In the first one file is received from a SOAP channel as attachment, and through a receiver file channel it is sent to a local folder in XI.
    In the second Interface, a File channel picks that files and througha SOAP channel sends it to the third party.
    Now the issue is,
    In the first interface the size of the file received and size of the file sent to XI folder is same, means no truncation is there.
    But when the File is picked by the file channel in second interface, the file gets trucated and it only picks a part of the file.
    Other interfaces are dealing fine with any file size, but only this particular interface is truncating data.
    Any help on this will be appreciated,
    Thanks,
    Vikas

    Hi Vikas,
          I dont know why you designed interface like 2 flow,you can avoid one interface as per question
    SOAP---->SAP PI----->File
    File-->SAPPI---->Receiver.current flow,
    you can make it SAOP--->pi--->Receiver,but i dont know why you developed as two flows..coming to truncation problem i  dont think problem with communication channel,my advice to you check in Moni Outbound payload,if it is taking whole message then the problem with Maping,some where you done wrong.
    else
    first open the content of the file in wordpad and see,and check communication details.
    Regards,
    Raj

  • Receiver file channel with ANSI format.

    Hi,
    I have developed file to file scenario for which sender file format is unicode and receiver file format is ANSI.
    There is no FCC at sender and receiver site. In interface we are just bypassing the file in PI, there is no ESR objects.
    I have configured sender channel for unicode in following way:
    File Type : Text
    file encoding : UTF-8
    I have configured receiver file channel for ANSI in following way:
    File Type : Text
    file encoding : i have tried with cp1252 and ISO8859-1
    When I run the interface I received receiver file in ANSI format. But when I open that file in notepad the content in the file is having spaces in between 2 characters like below.
    V O L 1 0 0 0 0 0 9
    Is any bady having idea about this problem?
    Thanks.
    Edited by: darshana-PI on Jan 23, 2012 6:32 PM

    Hi,
    The blanks in your target file might be created because your source file is encoded with UTF-16, not UTF-8. Try using one of these as an encoding in sender communication channel:
    UTF-16BE (16-bit Unicode character format, big-endian byte order)
    UTF-16LE (16-bit Unicode character format, little-endian byte order)
    UTF-16 (16-bit Unicode character format, byte order)
    Hope you'll find this useful,
    Greg

  • Error in Receiver File Channel...in MTB module     (Urgent)

    Hi,
    I am working on a Proxy to File scenario. I am using Message Transformation Bean in receiver file channel to convert xml file into fixed length file. I am getting an error : Transform: failed to execute the transformation: com.sap.aii.messaging.adapter.trans.TransformException: Error converting Message: java.lang.Exception: Exception in XML Parser (format problem?):java.lang.NullPointerException'; nested exception caused by: java.lang.Exception: Exception in XML Parser (format problem?):java.lang.NullPointerException
    in MTB step of audit log for comm channel.
    Please help me resolve this.
    Thanks,
    Jaya

    Hi ,
      "Transform: failed to execute the transformation:"
    Pls check ur data what u have to send .. any missing information or any special Chacters or any extra fields are available in the data, this type of transformation error raised.
    check once again ur mapping transformation and test the mapping in INTEGRATION REPOISTERY with the same data(what u have to send Previously).
    and also check ur adapter status in RWB.
    Regards,
    Sateesh N.
    Edited by: Sateesh N on Apr 21, 2008 1:53 PM

  • Sender File channel in "To be Delivered" status always- PI 7.4- ICO interface

    Hello All,
    We are testing one Integrated Configuration Object (ICO) which is developed on PI 7.4 system (dual stack). Scenario is simple file to file and it doesnt have any ESR part (pass thru interface).
    Sender channel (File adapter NFS based) is picking the file from IN directory and after which it is always in "To be Delivered" status and it never passed to Receiver file channel (NFS based).
    We tried stop and starting the channel, deleted and recreated the channel, reactivated the channel, cancelled and restar the message from Message monitoring page, Cache refresh from ID and CPA cache refresh which didn't help us.
    Below is audit log of sender File channnel:
    Please help us in solving this problem.
    Thanks,

    Hi Naresh,
    Have you tried Eng Swee Yeoh advices in this blog Handling and preventing messages stuck in To Be Delivered status?, like to set timeout and the mode Per file transfer.
    Regards

  • FCC file channel cannot process the empty file

    Hi,
    My requirement is like that a msg mapping getting two files from different sources and combining into one file and send to the receiver. There is a possibility that any one of the file can be empty.. now  problem is how to process the empty file in FCC file channel. When we trying to process the msg we are getting the error msg like "file end of exception". we already check the option empty file in file comm channel....under processing tab. But no use.Though we achieved through a module in sender channel. i want to know how to achieve this through simple content conversion by the FCC channel.
    In Content conversion. Record----> item,.. here what is mean ''? 0 to outbound or 1 to outbound?
    Regards
    Balaji

    Hi Balaji,
    here what is mean ''? 0 to outbound or 1 to outbound*
    means 0 to unbounded.
    Let me remind u ... the requirement cannot be achived in this way.. if file is empty.
    I hope u already checked the option..
    process empty files.
    I think u can handle this by, using a adapter module, in which..
    if file size(ASMA) is zero.. create a empty message and send it
    to the PI.
    Babu
    Edited by: hlbabu123 on Mar 9, 2010 2:36 PM

  • Help with add file name problem with Photoshop CS4

    Frustrating problem: Help with add file name problem with Photoshop CS4. What happens is this. When I am in PS CS4 or CS3 and run the following script it runs fine. When I am in Bridge and go to tools/photoshop/batch and run the same script it runs until it wants interaction with preference.rulerunits. How do I get it to quit doing this so I can run in batch mode? Any help is appreciated. HLower
    Script follows:
    // this script is another variation of the script addTimeStamp.js that is installed with PS7
    //Check if a document is open
    if ( documents.length > 0 )
    var originalRulerUnits = preferences.rulerUnits;
    preferences.rulerUnits = Units.INCHES;
    try
    var docRef = activeDocument;
    // Create a text layer at the front
    var myLayerRef = docRef.artLayers.add();
    myLayerRef.kind = LayerKind.TEXT;
    myLayerRef.name = "Filename";
    var myTextRef = myLayerRef.textItem;
    //Set your parameters below this line
    //If you wish to show the file extension, change the n to y in the line below, if not use n.
    var ShowExtension = "n";
    // Insert any text to appear before the filename, such as your name and copyright info between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextBefore = "Lower© ";
    // Insert any text to appear after the filename between the quotes.
    //If you do not want extra text, delete between the quotes (but leave the quotes in).
    var TextAfter = " ";
    // Set font size in Points
    myTextRef.size = 10;
    //Set font - use GetFontName.jsx to get exact name
    myTextRef.font = "Arial";
    //Set text colour in RGB values
    var newColor = new SolidColor();
    newColor.rgb.red = 0;
    newColor.rgb.green = 0;
    newColor.rgb.blue = 0;
    myTextRef.color = newColor;
    // Set the position of the text - percentages from left first, then from top.
    myTextRef.position = new Array( 10, 99);
    // Set the Blend Mode of the Text Layer. The name must be in CAPITALS - ie change NORMAL to DIFFERENCE.
    myLayerRef.blendMode = BlendMode.NORMAL;
    // select opacity in percentage
    myLayerRef.opacity = 100;
    // The following code strips the extension and writes tha text layer. fname = file name only
    di=(docRef.name).indexOf(".");
    fname = (docRef.name).substr(0, di);
    //use extension if set
    if ( ShowExtension == "y" )
    fname = docRef.name
    myTextRef.contents = TextBefore + " " + fname + " " + TextAfter;
    catch( e )
    // An error occurred. Restore ruler units, then propagate the error back
    // to the user
    preferences.rulerUnits = originalRulerUnits;
    throw e;
    // Everything went Ok. Restore ruler units
    preferences.rulerUnits = originalRulerUnits;
    else
    alert( "You must have a document open to add the filename!" );

    you might want to try the scripting forum howard:
    http://www.adobeforums.com/webx?13@@.ef7f2cb

  • SOMEONE PLEASE HELP WITH MISSING FILES XP PROBLEM

    i recently purchased an ipod touch, and all i want to do is get some music on it, and update the firmware, but i cant use itunes, cuz im getting 'there are some files missing' problem.
    I swear to god, if i dont get this fixed by the end of the week, im gonna post the latest video on youtube... on how to smash up apple products.
    Ive been trying NOT to buy apple products since the first dawn of time, but i do actually like the ipod touch. But, low and behold... the very reason why i never buy apple products has been confirmed!
    can someone PLEASE tell me if there is a solid fix for this? i have literally tried EVERYTHING before you ask. im at my wits end.
    Using XP home, all updates installed... latest itunes,

    It will probably help if you'll post the exact error message and when it's occurring. Otherwise we'll just be guessing, not that someone here might not have a good guess. I'm going to guess that this thread might help:
    http://discussions.apple.com/thread.jspa?messageID=11161893&#11161893
    Regards.

  • File sharing problems and horror story (nearly)

    I use Leopard on a MacBook Pro, a MacBook and a iMac G4 800 MHz (unsupported model).
    I have on the iMac and the MacBook Pro many users (the same ont he two machines) and I always use Fast User Switching.
    I have had very few problems with Leopard until now; I like it even if there are some glitches or some new features which are not my cup of tea (hierarchical menus missing from the dock, stacks useless when there are many items, FireWall impossibilities (?) to open specific ports, Back to my Mac working on a Lan but not from outside until now, problems with a few apps (Parallels networking erratic), ...
    Now about File Sharing.
    Let say my main account is user1 (Administrator), and I have another user2 also administrator, plus user3, user4 standard users.
    On the iMac I activate File Sharing.
    On the MacBookPro, as user1, if I connect to the iMac Server (using afp://IPaddress_of_theiMac/) I do NOT get the dialog
    "Enter your user name and password to access file server YYY
    Connect to server as Guest or as Registered User"
    but I directly get the dialog
    "Select the volumes you want to mount on YYY"
    From this, if I select user1 it mounts with full read/write permissions which is normal. It appears that I am connected with my Apple account user1&mac.com (same as mentionned in the Account panel of System Preferences).
    On the other hand, if I try to connect to the user2 account, I only get limited access although in the File Sharing Preferences, user1/iMac is mentionned with full Read/Write preferences for the Home Folder of user2.
    What is very surprising is that if I log on the MacBook Pro as user2, or user 3 or user4, then connect to the iMac, I first get the dialog to enter a user name and a password. This gives me access with the correct full permissions on user1/iMac or user2/iMac using the corresponding user name/password pair; this is the usual behaviour which is missing when trying to connect from user1/MacBook Pro.
    Now for the Horror Story!
    Trying to understand what was going on with the permissions of the user2/iMac account, I logged in to the iMac as user1, went to the Users folder and from there had a look on the informations about user2 home folder. In the lower part of the pannel, Sharing & Permissions says "You have no access" (which is normal) and this is followed by a table where users and permissions are listed. It seems user1 has Read and Write access in contradiction with the preceding phrase...
    Anyway, I tried to modify these authorizations for user2 by clicking on the lock of the Information pannel and entering name and password of the administrator. Didn't go farther than that. By mistake, I hit Command-Delete and user2 was GONE from the list AND NOT ONLY from the list in the Information window! Using Fast User Switching and going to user2, nothing left on the Desktop and NO Home anymore.
    In the System Preferences/Accounts panel, user2 was still mentionned.
    In the Users folder, no user2 folder anymore.
    Using once again Fast User Switching, I logged as user2 and got by magic an all new Home. Nothing left in Documents, Library or other user1 folders. Standard settings for icons, dock, etc.
    My first move has been to use a very recent backup to restore everything (Thank you Mike Bombich from Copy Cloner!).
    Once everything was back to normal, I had a look at the Trash from user1 and guess what, the Home folder of user2 was there, complete.
    So now I am left with two questions
    why is it I do not have the same dialogs when connecting from all the accounts although as far as I can see, configurations are the same?
    why is it possible, from an Information pannel to delete the account of another user?
    Thank you all for comments!

    For the file sharing problems, answer is found in
    http://docs.info.apple.com/article.html?artnum=306723

  • Error :Receiver File Channel not Initialized

    Hi all,
    I am using a file adapter at the receiver side with file content conversion option. When i post a message it shows an error in the message monitoring as "Reciever File Channel not initialized : Unable to proceed : null"
    Please Help.....

    Hi,
    Check if the adapter is active or
    check on this thread:
    File Adapter Not Initialized Error
    the error might be due to FCC. Jsut remove that and see ift he adapter works.
    Regards
    vijaya

  • File path problem

    I have looked an read through almost all the file path problem post possible and I am still having issues maybe one of you guys can help me, here are my files
    I am doing this as an example so that I can apply it to all of my file problems....
    Harold Timmis
    [email protected]
    Orlando,Fl
    *Kudos always welcome
    Attachments:
    pathexample.zip ‏122 KB

    First of all, to troubleshoot the problem it would help to put some filepath indicators at each point so that you can see what is going on. Also, in your exe having an error dialog "Simple Error Handler.vi" to let you know what LabVIEW didn't like in the exe.
    Now, when you run a top level ("Main.vi") and use the "Current VI's Path " in the development mode it returns <Filepath>\"Current path"\Main.vi. So stripping once will get you to  <Filepath>\"Current path" .    Now if you make it into an exe the "Current VI's Path" returns <Filepath>\"Current path"\"Name.exe"\Main.vi so you are "nested" one deeper.
    I use the following construct to determine whether the vi is being used as in the development environment or as an exe, the parse the path accordingly, although in this instance it is used to supply different directory names to a little more complex file system.
    Putnam
    Certified LabVIEW Developer
    Senior Test Engineer
    Currently using LV 6.1-LabVIEW 2012, RT8.5
    LabVIEW Champion

  • Error in Sender File Channel

    Dear all,
    I'm trying to execute a File to File scenario.But I'm getting this error in the sender file channel.
    "Putting message into send queue failed, due to: com.sap.aii.af.ra.ms.api.DuplicateMessageException: Message ID a0ff7230-8793-11dc-a4d5-001558e4827d(OUTBOUND) already exists in database: com.sap.sql.DuplicateKeyException: NWMssSQLServer JDBC DriverSQLServerViolation of PRIMARY KEY constraint 'PK__XI_AF_MSG__2B090089'. Cannot insert duplicate key in object 'dbo.XI_AF_MSG'.."
    The file is not getting picked, the processing mode is set to "Delete". Please help me out in resolving it.
    Any hep would be rewarded.
    Regards,
    Younus

    Hi,
    Check whether you have given the filename to other communication channel as well. Because it seems to execute another interface where you have a JDBC been used.
    If so change the file name in CC and in your file and check it once again.
    Regards,
    Nithiyanandam

  • Multiple Archive directories in Sender file channel

    Hi Experts,
    My requirment is to have multipple archive direcotories in Sender file channel.
    We have multiple source dirs  e.g.
    c:/abc/
    c:/bcd/
    c:/cde/
    and we want to archive the files from these source dirs to corresponding archive directories e.g.
    c:/abc/archive
    c:/bcd/archive
    c:/cde/archive
    I can see that we can have only 1 archive directory when the processing mode is kept as  "Archive"
    How can we achive the same , Please help
    Thanks in Advance,
    Jyoti

    Hello,
    I guess you don't have option to archive files in different directories using single CC.
    You can archive the files in 1 directory and then run a OS script, which will place the files in different directories (using NFS as protocol).
    Some reference:
    http://wiki.sdn.sap.com/wiki/display/XI/SAPXIFileAdapterOSCommandLine+Feature
    http://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/10392. [original link is broken] [original link is broken] [original link is broken]
    -Rahul

  • Java.lang.NullPointerException in File Channel

    Hi All,
    I have a File scenario running in system since 1 year. the sender file channel is scheduled at 4.00 AM in the morning every day. It works fine. But suddenly i got an error Error occurred while connecting to the FTP server "XXXXXXXXX:21": java.lang.NullPointerException
    The channel again ran at 4:20AM and it was successful. I am not able to find the exact error and the reason behind it.
    Can anybody suggest me what could be probable reason/s and how to find them? (I got this error in communication channel monitoring)
    Thanks in Advance.
    Sanjay

    Hi Install tcpgw and configure the TCPGateway in a way that it points to the FTP Server address
    Enter the following data in the screen
    Listen Port : 21
    Target Hostname : <Enter hostname>
    Target Port : 21
    /people/stefan.grube/blog/2007/03/29/troubleshooting-soap-http-and-mail-adapter-scenarios-with-tcpgateway
    /people/varadharajan.krishnasamy/blog/2007/01/09/troubleshooting-soap-message--xi

  • Receiver File channel for XML files: with carriage return

    Hi all,
    we are using a receiver FILE channel to generate an XML file that is sent to an external partner.
    The XML file looks good in a parser (IExplorer). But in fact there are not carriage return / line feeds between the XML tags
    of the XML payload in the file.
    Our partner now requires the XML file in a more vertical structure which means: for every tag a separate line (like it is displayed in a parser)
    Does anybody know a more general way to convert to a vertical XML structure (so with carriage return line feed).
    There is one entry in the SDN dealing with this topic but suggesting using an UDF. I think this is a very specific way.
    I don't think it is a good way to change/enhance the message mapping just because of a general formating change.
    Is it better to use an XSLT mapping as a second step in the interface mapping or a JAVA adapter module to convert ?
    any experiences? suggestions? examples?
    Thank you very much
    best regards
    Hans
    examples:
    original by XI receiver FILE adapter
    <?xml version="1.0" encoding="UTF-8"?>
    <MT_batchStatus><type>BS</type><header><message><messageSender>SENDER</messageSender><messageDate>20090723143720</messageDate> ... and so on
    required:
    <?xml version="1.0" encoding="UTF-8"?>
    <MT_batchStatus>
    <type>BS</type>
    <header>
    <message>
    <messageSender>SENDER</messageSender>
    <messageDate>20090723143720</messageDate>
    ... and so on

    >
    Hans Georg Walter wrote:
    > Is it better to use an XSLT mapping as a second step in the interface mapping or a JAVA adapter module to convert ?
    > any experiences? suggestions? examples?
    In such a case, the best is to write an generic XSLT or Java mapping that will attempt to do the pretty printing/formatting of the xml.
    The advantage of a generic one is that you can reuse the same class/jar for many other scenarios.
    so the flow will be as below in your interface mapping;
    1. your specific source to target mapping
    2. the generic formatting class

Maybe you are looking for

  • Wifi card

    Hi, Which wifi card do I need for the apple mac pro? 1,1 2006 Cheers, Adrian.

  • Still Awaiting Acknowledgement in SXMB_MONI - RFC Adapter

    Have a scenario where we are using an RFC adapter on the reciever end to bring in data into R/3. The message in SXMB_MONI is showing successfully processed, but in column "Ack Status" - the icon states "Still Awaiting Acknowledgement". As a result of

  • Loud clicking from G5 after waking from sleep mode

    Hello, I have a Power Mac G5 - 1.8 Ghz, 80 gig HD, 1.25 gig ram, OS 10.5.6.  I upgraded the OS to 10.5 from 10.3 about a year ago and have kept up with software updates.  Since performing the upgrade, the machine makes a moderately loud clicking nois

  • Global Application variable

    How do I set a global application variable in a Swing application? Namely MDI display opens a new window new window sets a variable close the new window and return to the MDI window MDI window needs to use the variable. Note: the new window is is its

  • Git version of bti fails to compile

    Hi, I'm trying to compile the git version of bti (an  console client for twitter and identi.ca) (http://www.kernel.org/pub/linux/kernel/people/gregkh/bti/ , <http://github.com/gregkh/bti/ http://github.com/gregkh/bti/>). When I run ./autogen.sh, it s