How to determine the size of an InputStream??

Hello,
I need to get the size of an inputstream. In fact, I am working with java.nio.channels and need to tranfer a file from within a Jar to the FileSystem.
I have created a ReadableByteChannel from the jar resource, and a FileChannel from the FileSystem destination. The problem is that to use the FileChannel .tranferFrom(..) I need the size of the src file. But, ReadableByteChannel has no size() method.
How can I determine the size of this InputStream??
advanced Thanx
here is code:
private void copyResourcesToFileSystem(){
          try{
                    String name = getFileName(); // gets the name
                    ReadableByteChannel srcChannel =
                         Channels.newChannel(this.getClass().getClassLoader().getResourceAsStream(("dtd/"+name)));
                    File newFile = new File(TempDirCreator.getXmlDir(),name);
                    FileChannel dstChannel = new FileOutputStream(newFile).getChannel();
                    dstChannel.transferFrom(srcChannel, 0, srcChannel.size());  // doesn't work -- there is no ReadableBC.size()
                    // lets close the show
                    srcChannel.close();
                    dstChannel.close();
          }catch(IOException x){x.printStackTrace();}
          catch(Exception ex){ex.printStackTrace();}
     }

In general the "size of an InputStream" is a meaningless concept. It's possible to have an InputStream that never terminates. So if you can't get a size from whatever you're reading from, you're out of luck.
I missed where you explained why you need the size. I've never felt the need to know how many bytes would be passing through my code when copying from input to output.

Similar Messages

  • How to determine the size (in pixels) of the current mode

    Hello.
    I am looking for a was to determine the size (horizontal and vertical pixels) of the current mode (SAPGUI window). I have already looked through the methods provided by class CL_GUI_CFW...
    CL_GUI_CFW=>GET_METRIC_FACTORS provides the size of you display (i.e. 1600 x 1200 pixels) and some other information I am not able to interprete.
    Futhermore I have had a look at the Methods CL_GUI_CFW=>COMPUTEPIXEL, but I don´t know how to use them.
    Has anybody of you any experiences in this topic? I would be grateful ...
    MIKE

    Sorry Manoj,
    but i didn´t find out, why these programs should be able to solve my issue. They just display a picture using the CL_GUI_PICTURE control.
    I am looking fo a way to resize a given control to the very maximum, so that it fills the whole SAPGUI window!
    Thanks anyway...
    MIKE

  • How to determine the size of the JVM process?

    Hi,
    How to determine the total process size of the JVM process (that includes Heap, Non Heap and Native memory)?
    Is there any command to obtain this value on Solaris (for Sun JVM)?
    I refer the process size to http://middlewaremagic.com/weblogic/wp-content/uploads/2010/11/Java_Heap_Diagram_12.jpg) here.
    Many thanks for your help in advance!

    Hi,
    Make sure that Total Heap + Native memory will be consider as total Memory.
    That means in 32 bit you will have only at most 4 GB for process + additional 2 GB for OS.
    So let assume if you have 4GM RAM then out of the 4GB you can allocate 2GB as Heap and 512m as Perm in case of Hot spot and remaining will be consider as Native memory.
    But in case of 64 bit will change you will have good amount of the memory so you can use plenty of Heap and Perm size.
    Still if you have query let me know.
    Regards,
    Kal

  • How to determine the size of an iMovie09 project?

    Hello:
    I recently created a nice video of about 2 hours in iMovie09. I "shared" it to iDVD but it was about 10% too big to burn. I went back to iMovie09 and removed some time to make the project smaller but how can I determine the size of my iMovie09 projects before I send them to iDVD? I know that both time and audio will affect the size of the iMovie09 project so the time of the video is not necessarily an accurate indicator.
    Thanks!

    Welcome to iMovie Discussions.
    As long as your movie is under about 1hr 50 minutes it should fit on a DVD.
    The thing which determines how much time is available on your DVD is usually the complexity of any Menus which you add in iDVD.
    With a simple Menu, which may "eat up" 10 mins of space, you should have room for 1h 50mins of movie.
    With complex, multi-level menus, your movie running time may be reduced by about 25 mins, or possibly more.
    Keep menus simple, and you should have space for about 1hr 50mins. It's always running time which counts, NOT "size" (in GB) of your movie.

  • How to determine the size of selected text

    Hi
    I'd like to draw a box around some selected text (a textRange), however I can't figure out how to detemine the size or position of the text.  The overall size of a textFrame is possible to find (not sure about position), but when you've got just a few characters selected I don't see any way to get the size or position.  Any ideas?

    You may have to do some testing of your own with this… I tested here and 'think' its OK but could have overlooked something… For me the best way to get this data is to outline the type store the info in a variable then undo the outlining process… You can then continue your script with info in hand… An example that draws a box over each selected character… I cheated with only the one text frame but you can resolve that? You could easy use math.min & math.max to draw around an array of bounds… I didn't bother with a load of tests it expects selected text range as is… have fun…
    #target Illustrator
    textBoxer();
    function textBoxer() {
              var i, doc, sel, start, end, spaceB4, spaceInc, mat, grp, count, boxes;
              doc = app.activeDocument;
              sel = doc.selection;
              start = sel.characterOffset-1; // Not zero based…
              end = start + sel.length;
              doc.selection = null;
              spaceB4 = doc.textFrames[0].contents.substr( 0, start );  // Cheated here you will need to find parent frame…
              mat = spaceB4.match( /\s/g ); // Resolve the lost of white space characters before selection
              mat != null ? spaceB4 = mat.length : spaceB4 = 0;
              spaceInc = doc.textFrames[0].contents.substr( 0, end );  // Here too…
              mat = spaceInc.match( /\s/g ); // Resolve the lost of white space characters in selection
              mat != null ? spaceInc = mat.length : spaceInc = 0;
              grp = doc.textFrames[0].createOutline(); // Items in new group are last to first order
              app.redraw();
              count = grp.compoundPathItems.length;
              boxes = Array();
              for ( i = 0; i < count; i++ ) {
                        boxes.push( grp.compoundPathItems[i].visibleBounds );
              boxes.reverse(); // Fix the order
              app.undo(); // Bounce back…
              app.redraw();
              start = start - spaceB4;
              end = end - spaceInc;
              for ( i = start; i < end; i++ ) {
                                  doc.pathItems.rectangle( boxes[i][1], boxes[i][0], boxes[i][2]-boxes[i][0], -boxes[i][3]- -boxes[i][1], false );
              app.redraw();

  • How to determine the size of recorded iPhone-video?

    After I record a video with my iPhone 4S, how can I tell what the size of that video file is?

    Welcome to iMovie Discussions.
    As long as your movie is under about 1hr 50 minutes it should fit on a DVD.
    The thing which determines how much time is available on your DVD is usually the complexity of any Menus which you add in iDVD.
    With a simple Menu, which may "eat up" 10 mins of space, you should have room for 1h 50mins of movie.
    With complex, multi-level menus, your movie running time may be reduced by about 25 mins, or possibly more.
    Keep menus simple, and you should have space for about 1hr 50mins. It's always running time which counts, NOT "size" (in GB) of your movie.

  • How to determine the size of a flat file attachment in a mail sender cc?

    Hi
    I use PI 7.11
    I have a scenario where a flat file attachment is being picked up by a MailSender adapter and if the size of the attached flat file is larger that 500 bytes the receiver is A and if the attachment is less that 500 bytes the receiver is B.
    I have checked the Context Object list in the Conditions section of Receiver Determination, and it seems, that only the file adapter allows for validation on the file size.
    I contemplated an extended receiver determination but the attachment is a flat file which just needs to be passed thru without being converted to an XML document, so my source document is not of XML format.
    An other but not very nice way would be to use an intermediate folder to drop the attachment in and from there use a file sender adapter and thus get access to the filesize attribute in my receiver determination, but I would like to avoid this.
    Any suggestions?
    BR MIkael

    Hi
    I have decided to make a module, where I plan to place the size of the attachment in the Dynamic Configuration variable "ProcessStep", but to my surprise, it seems that all the context objects in the receiver determination condition section are of type String and hence it is not possible to make a condition where I test for whether the value is smaller than say 500!? Only equal, NOT equal and LIKE are available (EX seems to be disabled as this probably only works in an xpath.
    Would one way be to use the xpath expression like this ns1:Main\ProcessStep < 500 where ns1: http://sap.com/xi/XI/System?
    MIkael

  • How to determine the size of client in sap system

    Dear Exports,
                         Pls suggest me how we can check the size of the client in oue sap system.
    Thanks in advance.

    Hi Amit,
    If you are not able to check the note 118823 or you can't able to find the solution. Just start client copy in test mode, there you can get the size of the client then you can cancel the client copy(which is in test mode).
    Hope it will resolve your doubt.
    Thanks
    Kishore

  • How to determine the size of The Entire iPhoto Library

    Hello,
    Can someone tell me if its possible to determine the entire size of my iPhoto library?
    Thanks

    The size of the Library when you do a "get info" for it in the finder will be larger because it includes all the data files, thumbnail files, originals and edited originals.
    The size of the library when you do a "get info" of the library while within iPhoto will just give you the size of all the images.
    As for my avatar I just did this;
    I am not sure what picture you meant, but yes I should be there somewhere and I have 2 children and one grand daughter.
    The sausage making was lots of fun.
    ☺Lori

  • How to determine the size of a file on application server

    Hello,
    using open dataset I have created a file on the application server and have put some data into the file.
    Now I want to know the size of this file.
    Is there a function module to do this ?
    Best regards
    Michael

    Hi,
    Use Function module   'EPS_GET_FILE_ATTRIBUTES'
    DATA fsize TYPE epsf-epsfilsiz.
    CALL FUNCTION 'EPS_GET_FILE_ATTRIBUTES'
      EXPORTING
        file_name =     " here provide filename
        dir_name  =    "  here provide directory
      IMPORTING
        file_size = fsize.
    WRITE: 'File size' , fsize.
    Regards,
    Ravi

  • How to determine the field size

    I am going to make a multiplatform application that hopefully
    will run on linux and windows 2000.If the os is 2000, then I will use
    vb.net/aspx else I'll use java servlets. I make the connection
    to the web server ( through HTTP) not directly to database server.
    So, the resultset will be stored in the String object. The columns
    will be separated by delimeter. Our problem is how to determine
    the size and type of the fields of mssql,oracle and postgres database
    so that we can include it in the String object.
    Ex.
    String sResultSet=new String();
    ResultSet rs=statement.executeQuery(sSQL);
    while(rs.next()){
    sResultset=sResultSet + rs.getString(field1) + "||" + rs.getString(field2) + "||";
    vertical bars acts as delimeter
    supposedly this is the code:
    sResultset=sResultSet + rs.getString(field1) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||" + rs.getString(field2) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||";
    supposedly this is the code if rs.getFieldType() and rs.getFieldSize() methods are existing
    Anyone can give me an idea how to get the field type and field size of the database?
    thanks in advance

    Yes, but I dont know how to do it.
    Can you give me an example of using it.
    Thanks in advance

  • Determine the Size of an Object in ObjectInputStream

    Hi all,
    I have a quick question. I have a class that is being written over a socket using ObjectOutputStream and ObjectInputStream. I want to be able to set the buffer size of the socket to fit only ONE object. Can anybody tell me how to determine the size of that object?
    (Note, the object has a Properties object within it, but for the time being, it can be assumed that properties object will always be the same.)
    - Adam

    Having written it to the outputStream, thought, can
    the size be determined somehow by the inputStream?No, it can't
    This is related to my previous question (on Pushlets
    and Thread Priorities). I didn't read that one.
    I believe that it's possible
    that multiple threads are trying to write to the
    socket at the same time, and I cannot synchorize the
    input stream to get a lock on it. Do you mean the outputstream? Why can't you synchronize the method that writes to the outputstream?
    I thought this
    might be causing the data to not be sent over the
    socket until all the threads have finished. That doesn't sound correct. But you could call the flush method when an object is written.
    I
    figured if I reduced the size of the socket buffer,
    it would only accept a single object, eliminating
    this problem?I don't think so.
    /Kaj

  • How Can I Determine the Size of the 'My Documents' Folder for every user on a local machine using VBScript?

    Hello,
    I am at my wits end into this. Either I am doing it the wrong way or it is not possible.
    Let me explain. I need a vb script for the following scenario:
    1. The script is to run on multiple Windows 7 machines (32-Bit & 64-Bit alike).
    2. These are shared workstation i.e. different users login to these machines from time to time.
    3. The objective of this script is to traverse through each User Profile folder and get the size of the 'My Documents' folder within each User Profile folder. This information is to be written to a
    .CSV file located at C:\Temp directory on the machine.
    4. This script would be pushed to all workstations from SCCM. It would be configured to execute with
    System Rights
    I tried the script detailed at:
    http://blogs.technet.com/b/heyscriptingguy/archive/2005/03/31/how-can-i-determine-the-size-of-the-my-documents-folder.aspx 
    Const MY_DOCUMENTS = &H5&
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(MY_DOCUMENTS)
    Set objFolderItem = objFolder.Self
    strPath = objFolderItem.Path
    Set objFolder = objFSO.GetFolder(strPath)
    Wscript.Echo objFolder.Size
    The Wscript.Echo objFolder.Size command in the script at the above mentioned link returned the value as
    '0' (zero) for the current logged on user. Although the actual size was like 30 MB or so.
    I then tried the script at:
    http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_27869829.html
    This script returns the correct value but only for the current logged-on user.
    Const blnShowErrors = False
    ' Set up filesystem object for usage
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objShell = CreateObject("WScript.Shell")
    ' Display desired folder sizes
    Wscript.Echo "MyDocuments : " & FormatSize(FindFiles(objFSO.GetFolder(objShell.SpecialFolders("MyDocuments"))))
    ' Recursively tally the size of all files under a folder
    ' Protect against folders or files that are not accessible
    Function FindFiles(objFolder)
    On Error Resume Next
    ' List files
    For Each objFile In objFolder.Files
    On Error Resume Next
    If Err.Number <> 0 Then ShowError "FindFiles:01", objFolder.Path
    On Error Resume Next
    FindFiles = FindFiles + objFile.Size
    If Err.Number <> 0 Then ShowError "FindFiles:02", objFile.Path
    Next
    If Err.Number = 0 Then
    ' Recursively drill down into subfolder
    For Each objSubFolder In objFolder.SubFolders
    On Error Resume Next
    If Err.Number <> 0 Then ShowError "FindFiles:04", objFolder.Path
    FindFiles = FindFiles + FindFiles(objSubFolder)
    If Err.Number <> 0 Then ShowError "FindFiles:05", objSubFolder.Path
    Next
    Else
    ShowError "FindFiles:03", objFolder.Path
    End If
    End Function
    ' Function to format a number into typical size scales
    Function FormatSize(iSize)
    aLabel = Array("bytes", "KB", "MB", "GB", "TB")
    For i = 0 to 4
    If iSize > 1024 Then iSize = iSize / 1024 Else Exit For End If
    Next
    FormatSize = Round(iSize, 2) & " " & aLabel(i)
    End Function
    Sub ShowError(strLocation, strMessage)
    If blnShowErrors Then
    WScript.StdErr.WriteLine "==> ERROR at [" & strLocation & "]"
    WScript.StdErr.WriteLine " Number:[" & Err.Number & "], Source:[" & Err.Source & "], Desc:[" & Err.Description & "]"
    WScript.StdErr.WriteLine " " & strMessage
    Err.Clear
    End If
    End Sub
    The only part pending, is to achieve this for the 'My Documents' folder within each User Profile folder.
    Is this possible?
    Please help.

    Here are a bunch of scripts to get folder size under all circumstances.  Take your pick.
    https://gallery.technet.microsoft.com/scriptcenter/site/search?query=get%20folder%20size&f%5B0%5D.Value=get%20folder%20size&f%5B0%5D.Type=SearchText&ac=2
    ¯\_(ツ)_/¯

  • How to determine the scratch disc size?

    hello,
    once i was reading an adobe pdf "How to get better performance in photoshop cs5" - that was in 2009 or 2010, and may be outdated, but there was a calculation method
    to determine the size of a scratch disc. (similar calculation see below, if i can remember right)
    i am asking myself, how can i determine the correct size of an external SSD-scratch disc, only used by photoshop (completely empty):
    should i buy a 128GB or 256GB or 512GB SSD which is only reserved for photoshop?
    basic question 1 : i guess i should avoid to set the internal SSD as photoshop scratch disc, as it slows down everything?
    basic question 2 : in sense of maximum performance: better buy an external USB3.0 or thunderbolt SSD? will photoshop really use the extra thunderbolt speed when swapping data?
    secondary question:
    can i calculate the size regarding my daily working habits?
    i am mainly working like this:
    - with my imac 27" late 2013 with 32GB RAM and 256 GB internal pci-e SSD (800 MB/sec), which will stay always half empty for performance reasons.
    - OSX 10.8 mountain lion and 10.9 mavericks soon
    - photoshop cs5, cs6 and cc (always without extended)
    - 8bit and 16bit mode
    - only RGB
    - with latest phocus/Hasselblad and canon RAW Files which produce a basic .psb document at ...
    - 10.000 x 7000 px at 300dpi
    - with average 10 - 40 main image layers and 20-50 adjustement layers (try to reduce that in 16bit)
    - .psb file is 2-20 GB big (file in finder)
    - 16bit file compression is off, when saving .psb files (faster handling)
    -  set photoshop to 70% ram usage (from 32GB RAM)
    i wonder how to calculate ?
    for example:
    10.000 x 7000 px at 300dpi needs for one image layer at 16bit: 2GB RAM in photoshop cs6 or cc (just as a number), this may be wrong
    so lets take 2GB RAM and multiply with 10 image layers in my .psb file (16bit) = 20 GB RAM, and multiply with 20 adjustment layers (guess they need less ram, for one lets say 500MB) = 20GB + 10GB = this 16bit .psb layer file would need 30GB RAM, so when i have 32GB in my imac, i set cs6 or cc to 70% ram usage, it misses at least round 8-10GB RAM > can i guess that photoshop would swap these 8GB onto my scratch disc? or do i miss something important in my thinking?
    tricky thinking
    thanks for help

    station_two wrote:
    The rule of thumb I follow says to figure on 50 to 100 times the size of your largest file ever multiplied by the number of files you have open.  I have seen the scratch file exceed 300 GB once, an admittedly rare occurrence, but it often exceeds 200 GB when stitching large panoramas and the like.
    As an example—and stressing that I'm aware that others have even more scratch space than I do—I keep two dedicated, physically separate hard drives as my primary and secondary Photoshop scratch disks and a lot of GB free on my boot drive for the OS.  I also have 16 GB of RAM installed.
    Additionally, if you only have a single HD, i.e. your boot drive, you'd need it to be large enough to accommodate both the swap files of the OS as well as Photoshop's scratch.
    - i dont use HDD anymore only SSDs, both internal and external
    - i set history state to only 5 or 6, to improve performance
    - i set cache size to 4 and tiles to "big and flat" with 1028kb (there is no "big and much layers" option)
    - is this still the rule of thumb? i read it in 2009 , too, guess it was outdated, as cs6 and cc have improved codes in terms of performance?
    - if you say "50 to 100 times the size of your largest file ever multiplied by the number of files you have open.":
    i will not open more than one document at same time to prevent performance lags, so lets calc like: dokument size in finder (you mean in finder or doc. size shown in photoshop?) = e.g. 5GB x 100 = 500GB, so my external scratch disc SSD, i would buy now, should be at least 500GB, USB 3.0 or thunderbolt ... maybe better thunderbolt, yes? with usb 3.0 i could gain 300MB/sec if thats enough for photoshop?
    thanks

  • How do I determine the size of an event (cmd I does not show any size for events).

    How do I determine the size of an Event in iPhoto? (Cmd + I does not show size information at the event level).

    If you're running iPhoto 8 (09) select the event and look at the Info pane at the lower left hand corner of the window.  It will give you the number of photos and size:
    for iPhoto 9 (11) open the Event, select all of the photos in it and open the Info drawer at the right by typing Command+i.  The number of photos and size will be at the top of the Info drawer.
    OT

Maybe you are looking for