Splitting 1GB Files // Problem with FileStream class

Hi, in my Air (2 beta) app i'm splitting large files to upload them in  smaller chunks.
Everything works fine, until i choose files larger  than 1GB?
This might be the Problem:
var  newFile:File =  File.desktopDirectory.resolvePath(filename);                        
trace(newFile.size);
//  8632723886  (About 8GB correct file size)
BUT if i use the FileStream Class instead:
var stream:FileStream = new  FileStream();
stream.open(new File(filename), FileMode.READ);
trace(stream.bytesAvailable)
//  42789294 ("wrong" file size?)
If i run the same code with files smaller  than 1GB stream.bytesAvailable returns the same result as newFile.size.
Is there a  limitation in the FileStream class or is my code wrong?
Thanks!

use asynchronous file handling method. i.e use (filestream object).openAsync(file,filemode.read). here is the implementation :
private var fileCounter:int = 0;
private var bytesLoaded:int = 0;
private var filePath:String = "D:\\folder\\";
private var fileName:String = "huge_file";               
private var fileExtension:String = ".mkv";
private var file:File = new File(filePath+fileName+fileExtension);
//split size = 1 GB
private var splitSize:int = 1024*1024*1024;
private var fs:FileStream = new FileStream();
private var newfs:FileStream = new FileStream();
private var byteArray:ByteArray = new ByteArray();
private function init():void{
     fs.addEventListener(Event.COMPLETE,onFsComplete);
     fs.addEventListener(ProgressEvent.PROGRESS,onFsProgress);
     newfs.open(new File(filePath+fileName+fileCounter+fileExtension),FileMode.WRITE);
     fs.openAsync(new File(filePath+fileName+fileExtension),FileMode.READ);
private function onFsComplete(e:Event=null):void{                    
     fs.readBytes(byteArray,0,fs.bytesAvailable);                    
     newfs.writeBytes(byteArray,0,Math.min(splitSize-bytesLoaded,fs.bytesAvailable));
     for(var i:int = 0; i < byteArray.length; i+=splitSize){
          newfs.close();
          newfs.open(new File(filePath+fileName+fileCounter+fileExtension),FileMode.WRITE);
          newfs.writeBytes(byteArray,i,Math.min(splitSize,byteArray.length-i));
          fileCounter++;
          trace("Part " + fileCounter + " Complete");
private function onFsProgress(e:ProgressEvent):void{
     if((bytesLoaded+fs.bytesAvailable)==file.size){
          onFsComplete();                         
     else if((bytesLoaded + fs.bytesAvailable)>=splitSize){
          fs.readBytes(byteArray,0,splitSize-bytesLoaded);
          newfs.writeBytes(byteArray,0,byteArray.length);
          newfs.close();
          bytesLoaded = fs.bytesAvailable;
          fs.readBytes(byteArray,0,bytesLoaded);
          fileCounter++;
          newfs.open(new File(filePath+fileName+fileCounter+fileExtension),FileMode.WRITE);                         
          newfs.writeBytes(byteArray,0,byteArray.length);
          byteArray.clear();
          trace("Part " + fileCounter + " Complete");
     else{
          bytesLoaded+=fs.bytesAvailable;
          fs.readBytes(byteArray,0,fs.bytesAvailable);
          newfs.writeBytes(byteArray,0,byteArray.length);
          byteArray.clear();     
cheers!

Similar Messages

  • Problems with inner classes in JasminXT

    I hava problems with inner classes in JasminXT.
    I wrote:
    ;This is outer class
    .source Outer.j
    .class Outer
    .super SomeSuperClass
    .method public createrInnerClass()V
         .limit stack 10
         .limit locals 10
         ;create a Inner object
         new Outer$Inner
         dup
         invokenonvirtual Outer$Inner/<init>(LOuter;)V
         ;test function must print a Outer class name
         invokevirtual Outer$Inner/testFunction ()V
    .end method
    ;This is inner class
    .source Outer$Inner.j
    .class Outer$Inner
    .super java/lang/Object
    .field final this$0 LOuter;
    ;contructor
    .method pubilc <init>(LOuter;)V
         .limit stack 10
         .limit locals 10
         aload_0
         invokenonvirtual Object/<init>()V
         aload_0
         aload_1
         putfield Inner$Outer/this$0 LOuter;
         return
    .end method
    ;test
    .method public testFunction ()V
         .limit stack 10
         .limit locals 10
         ;get out object
         getstatic java/io/PrintStream/out  java/io/PrintStream;
         aload_0
         invokevirtual java/lang/Object/getClass()java/lang/Class;
         ;now in stack Outer$Inner class
         invokevirtual java/Class/getDeclaringClass()java/lang/Class;
         ;but now in stack null
         invokevirtual java/io/PrintStream/print (Ljava/lang/Object;)V
    .end methodI used dejasmin. Code was equal.
    What I have to do? Why getDeclatingClass () returns null, but in dejasmin code
    it returns Outer class?

    Outer$Inner naming convention is not used by JVM to get declaring class.
    You need to have proper InnerClasses attribute (refer to http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html#79996)
    in the generated classes. Did you check using jclasslib or another class file viewer and verified that your .class files have proper InnerClasses attribute?

  • Getting problem with DOMImplementation classes method getFeature() method

    hi
    getting problem with DOMImplementation classes method getFeature() method
    Error is cannot find symbol getFeature()
    code snippet is like...
    private void saveXml(Document document, String path) throws IOException {
    DOMImplementation implementation = document.getImplementation();
    DOMImplementationLS implementationLS = (DOMImplementationLS) (implementation.getFeature("LS", "3.0"));
    LSSerializer serializer = implementationLS.createLSSerializer();
    LSOutput output = implementationLS.createLSOutput();
    FileOutputStream stream = new FileOutputStream(path);
    output.setByteStream(stream);
    serializer.write(document, output);
    stream.close();
    problem with getFeature() method

    You are probably using an implementation of DOM which does not implement DOM level-3.

  • Anyone know if the long standing duplicate files problem with File History has been fixed yet?

    There are loads of public threads about the duplicate files problem
    with Windows 8/8.1 File History backup system.
    From all the threads I've looked at, there seems to be no solution,
    and no acknowledgement from MS that they can even repro the problem
    (which surprises me considerably as there are so many people who
    notice the problem).
    Is anyone aware of whether MS (may) have fixed this for Win10?
    Are MS aware of the problem and if they're able to fix it?
    Dave - with many GB of duplicated files in File History :)

    Hmm, is that the attitude MS would recommend? :)
    Why would I care what Microsoft would recommend?
    Clearly you don't, and you appear to have missed my smiley. Calm down
    Noel, many of us are as annoyed by aspects of modern Windows as you
    are. :)
    I'm all about making Windows actually WORK/./
    Aren't we all? Windows is software I use too many hours every day, I
    along with many millions of others need it to work really well. You
    are not alone.
    When they implement something that doesn't work, and even if it did work doesn't do what's needed - and/beyond that/ they remove features people DO need (such as the GUI for Windows Backup), I see no wrong in advising people of the way things
    really are.
    File History essentially does work - it's saved me a couple of times
    in the past couple of weeks. It just has a highly annoying habit of
    creating 100% duplicates of some files for no apparent reason. If MS
    have fixed that I won't have any known complaints about it.
    If you don't like it, you don't have to use it. I generally like it, I
    just want to see that its fixed.
    Dave

  • Bat file problems with 5.2(3)

    I'm having bat file problems with CCM 4.2(3) with bat version 5.2(3). When adding phone/users getting an error number -2146828279 with this message "Description -Subscript Out of range".

    Hi Denis,
    Just wanted to know if the description contained a comma? There was a bug in a previous BAT version that would affect phone/user inserts if there was a comma.
    CSCsb61425 Bug Details
    Headline BAT insert fails if phone description contains comma
    This was in BAT 5.1.4
    Hope this helps!
    Rob

  • Problems with loading Classes from a Directory of a jar file.

    Hi Guys,
    i have a problem with my programm. It works greatly in my eclipse platform. but there are all classes in my default folder. I want to add a plugin function now. My Abstract classes are in in my default folder and my doughter classes are in my plugin-folder called plugin.
    I look what is in the pluginfolder -> all my doughter classes. but i every time get a Class Cast Exception and an ClassNotFoundException.
    How can i do that ? Current i do it with Class.forName(frames.substring(0,frames[i].indexOf(".class")));
    best regards flo

    http://java.sun.com/j2se/1.3/docs/tooldocs/win32/classpath.html

  • Problems with importing classes in Java

    Hello,
    i have some problems with a simple project.
    The structure is like this:
    web-inf/classes/databeans/loginexistinguserform.java
    web-inf/classes/formactions/loginexistinguseraction.java
    loginexistinguserform.java :
    package databeans;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionError;
    import org.apache.struts.action.ActionMapping;
    import javax.servlet.http.HttpServletRequest;
    public class LoginExistingUserForm extends ActionForm
         String userid;
         String password;
         public String getUserid(){return userid;}
         public void setUserid(String newUserid){userid=newUserid;}
         public String getPassword(){return password;}
         public void setPassword(String newPassword) {password=newPassword;}
         public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){
              ActionErrors errors=new ActionErrors();
              if(this.userid==null||this.userid.equals(""))
                   errors.add("user",new ActionError("error.userid.required"));
              if(this.password==null||this.password.equals(""))
                   errors.add("pass",new ActionError("error.password.required"));
              return errors;
    }loginexistinguseraction.java
    package formactions;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import databeans.LoginExistingUserForm;
    public class LoginExistingUserAction extends Action
         public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
         throws IOException, ServletException
              LoginExistingUserForm loginData=(LoginExistingUserForm)form;
              if(loginData.getUserid().equals("Admin")&&loginData.getPassword().equals("Parola"))
                   return mapping.findForward("successLogin");
              else
                   return mapping.findForward("failureLogin");
    }I can complie succesfully loginexisitinguserform.java but problems appears when i want to compile the second file, loginexistinguseraction.java with command: javac loginexistinguseraction.java
    C:\ApacheGroup\Tomcat\webapps\PersonalWeb\WEB-INF\classes\formactions>javac loginexistinguseraction.java
    loginexistinguseraction.java:10: package databeans does not exist
    import databeans.LoginExistingUserForm;
    ^
    loginexistinguseraction.java:17: cannot find symbol
    symbol : class LoginExistingUserForm
    location: class formactions.LoginExistingUserAction
    LoginExistingUserForm loginData=(LoginExistingUserForm)form;
    ^
    loginexistinguseraction.java:17: cannot find symbol
    symbol : class LoginExistingUserForm
    location: class formactions.LoginExistingUserAction
    LoginExistingUserForm loginData=(LoginExistingUserForm)form;
    ^
    3 errors
    I have the CLASSPATH variable setup tu C:/Sun/Appserver/lib/j2ee.jar
    Can someone help me ? Thank you in advance !

    Thank you very much ! It worked. I'm really new in Jav a programming.
    Now i have encoutered another problem. When i want to login, and enter user name and password i am redirected to a login.do page, instead of Welcome.jsp
    Here is Login.jsp:
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@page contentType="text/html; charset=ISO-8859-1"%>
    <html>
    <head><title>Login Form</title></head>
    <body>
    <html:errors/>
    <html:form action="/login">
    <table border="0" width="200">
    <tr>
         <td>User Name:</td>
         <td><html:text property="userid" maxlength="13"/></td>
    </tr>
    <tr>
         <td>Password:</td>
         <td><html:password property="password" maxlength="13"/></td>
    </tr>
    </table>
    <br />
    <html:submit value="Login"/>
    </html:form>
    </body>
    </html>and here is struts-config.xml :
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
              "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd">
    <struts-config>
    <!--========================beans for HTML form data=======================-->
    <form-beans>
         <form-bean name="loginBean" type="databeans.LoginExistingUserForm"/>
    </form-beans>
    <!--========================Action Mappings================================-->
    <action-mappings>
         <action path="/login" type="formactions.LoginExistingUserAction" name="loginBean" input="/Login.jsp" scope="session">
              <forward name="succesLogin" path="/pages/Welcome.jsp" redirect="true"/>
              <forward name="failureLogin" path="/pages/Diverse.jsp" redirect="true"/>
         </action>
    </action-mappings>
        <message-resources parameter="MessageResources" />
    </struts-config>

  • Problem with JFrame class.

    To risolve my problem i need for few diferent frame
    ( for esample in one i put JTextFild that take the user input, in a nother one i need for program output ) . But, th problem is, all my frames using the same object.
    If i construct diferent JFrame window class i have problem that i don't acess in the same object from all the window. And if i dont use a object, i have static acess .
    I risolve the problem with 1 JFrame class with diferent constructors, but i wont a diferent way to risolve my problem, because there are few windows.
    Help me.....

    Make the class that extends JFrame an inner class of the the main class. You can then access all members of the outer class.

  • With conversion to Leopard, file problems with networked Windows computer

    Last night I did an Archive & Install from Tiger to Leopard on my Intel MacBook Pro. Today, I had trouble finding the other computers at my office. Once I finally got them to show up, I opened a Word file found on another computer, made some changes, and when I tried to save it, I got this message: "This is not a valid file name. Try one or more of the following: *Check the path to make sure it was typed correctly. *Select a file from the list of files and folders." Since this file already existed and I wasn't changing the name, I thought this was odd, but I changed the name from "Seating Chart 3-8-08" to "SeatingChart3-8-08" in case Leopard didn't like spaces when talking to Windows, but I got the same error message. Finally I gave up, not knowing what to do, then discovered that it had in fact saved my file. Still, every time I try to save ANY Word document from the shared folder of the Windows computer, I get the same error message endlessly until I choose "Don't Save."
    When I try to open an Excel file from that computer, it won't even open; it says " 'File Name.xls' cannot be accessed. This file may be Read-Only, or you may be trying to access a Read-Only location. Or, the server the document is stored on may not be responding." As with the Word file problem above, I did not have any problem accessing the files until I converted to Leopard.
    The Windows machine is Windows XP using Microsoft Office 2003; I have Microsoft Office 2004 on my machine.

    See if this Link, by Pondini, offers any insight to your issue...
    Transfer from Old  to New
    http://pondini.org/OSX/Setup.html
    Also, See here if you haven't already...
    http://www.apple.com/support/switch101/     Switching from PC

  • Airport Extreme, Airdisk, and Vista - large file problem with a twist

    Hi all,
    I'm having a problem moving large-ish files to an external drive attached to my Airport Extreme SOMETIMES. Let me explain.
    My system - Macbook Pro, 4gb ram, 10gb free HD space on macbook, running latest updates for mac and vista, external hard drive on AE is an internal WD in an enclosure w/ 25gb free (its formatted for pc, but I've used it directly connected to multiple computers, mac and pc, without fail), AE is using firmware 7.3.2, and im only allowing 802.11n. The problem occurs on the Vista side - havent checked the mac side yet.
    The Good - I have bit torrents set up, using utorrent, to automatically copy files over to my airdisk once they've completed. This works flawlessly. If i connect the hard drive directly to my laptop (macbook running bootcamp w/ vista, all updates applied), large files copy over without a hitch as well.
    The Bad - For the past couple weeks (could be longer, but I've just noticed it recently being a problem - is that a firmware problem clue?) If i download the files to my Vista desktop and copy them over manually, the copy just sits for a while and eventually fails with a "try again" error. If i try to copy any file over 300mb, the same error occurs.
    What I've tried - well, not a lot. The first thing i did was to make sure my hard drive was error free, and worked when physically connected - it is and it did. I've read a few posts about formatting the drive for mac, but this really isnt a good option for me since all of my music is on this drive, and itunes pulls from it (which also works without a problem). I do however get the hang in itunes if i try to import large files (movies). I've also read about trying to go back to an earlier AE firmware, but the posts were outdated. I can try the mac side and see if large files move over, but again, i prefer to do this in windows vista.
    this is my first post, so im sure im leaving out vital info. If anyone wants to take a stab at helping, I'd love to discuss. Thanks in advance.

    Hello,
    Just noticed the other day that I am having the same problem. I have two Vista machines attached to TC w/ a Western Digital 500 gig USB'd. I can write to the TC (any file size) with no problem, however I cannot write larger files to my attached WD drive. I can write smaller folders of music and such, but I cannot back up larger video files. Yet, if I directly attach the drive to my laptop I can copy over the files, no problem. I could not find any setting in the Airport Utility with regards to file size limits or anything of the like. Any help on this would be much appreciated.

  • File problem with accent / CS4 Mac

    Hi
    I"m using CS4 on MAC OSX 10.5.7
    I have problem with filename containing accents like 'é'
    For example : I browse for a file called 'testé.xml' using kOpenFileDialogBoss, and then get the resulting IDFile. From this IDFile I get the path in a PMString with the function FileUtils::SysFileToPMString.
    My problem is that character 'é' has a strange representation, instead of having the correct path I get 'teste<0301>.xml' and if I want to use this path with a fopen function or even to show it into a TextEditBoxWidget it'll fail.
    I've look into SnpChooseFile sample and the problem is the same. In the log I also get that strange representation.
    Have you encountered this problem?
    Thanks for your help

    Have a look at FileUtils::DecomposeUnicode and NormalizeUnComposedUnicodeChars. Use the first to convert before using i.e. FileUtils::PMStringToSysFile() and the later afetr i.e. FileUtils::IDFileToPMString().
    HTH

  • Problem with loading classes!!!

    I am loading classes using
    // Open File
    InputStream jarFile = new BufferedInputStream(new FileInputStream(
    pluginPath));
    // Get Manifest and properties
    Attributes attrs = new JarInputStream(jarFile).getManifest().
    getMainAttributes();
    jarFile.close();
    // Read Main Class
    String mainClass = attrs.getValue("Protocol-Class");
    // Load all classes from jar file without giving classpath
    URL url = new URL("jar:file:" + pluginPath + "!/");
    JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
    URL[] urls = new URL[] {
    url};
    ClassLoader classLoader = new URLClassLoader(urls);
    // Create new instance of protocol
    Protocol protocol = (Protocol) classLoader.loadClass(mainClass).
    newInstance();
    I am loading classes one by one say a order A, B, C. In my case class c extends class A. So I am loading class A first and later B and finally C. But I am getting exceptions when loading class C that Class A is unknown.The following exception is thrown
    java.lang.NoClassDefFoundError: com/a/A at java.lang.ClassLoader.defineClass0(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:537)
    Please give me a solution to make it run.

    You create a new class loader for each class. The class loaders are independent, and so the class hierarchies they load are independent. Class A loader by classLoaderOne doesn't see class B loader by classLoaderTwo - they are loaded into their own sandboxes.
    Either load everything with one class loader or create the class loaders in a hierarchy. To create a hierarchy use the class loader constructor that takes a parent class loader as a parameter. One class loader may be easier because then you don't need to worry about loading order.

  • RAW Files problems with 5DMarkIII

    I recently started shooting RAW in my new 5DMarkIII but everytime I try to transfer those files to Aperture 3 it crashes and no file can be transfered to my computer. I have the app up to date and the firmware of the camera is the last one. I have no problems with the JPG files, but the RAW files crashes Aperture and I cant get them on my computer!

    Thanks! and I apologize if my english is not good enough.
    No problem your english is probably better than mine!
    Update: In the last two hours Aperture could transfer a couple of files but I had to do it one by one. Then, I attempted to transfer a whole group of files, it crashed again.
    This looks like just one of your images on the card is defective. Try to import without rendering previews: Turn off the Preference: "Previews > new Projects automatically generate previews" before importing.
    Then create the previews one by one after import. Probably Aperture will crash when you try to render a preview for the defective  image, but then you will know which image to remove.
    Regards
    Léonie

  • H.264 .mov files problem with 2-pass vbr in DVD SP4

    I have converted some VHS tapes by connecting the VCR to my camcorder (as a AC/DC bridge) and the camcorder to my macbook pro via firewire, and record using FCP into .mov files.
    However, these files are huge (13 GB for an hour), and so I shrinked them down by exporting them (using QT pro) into .mov file via h.264 codec.
    However, when I try to convert these already shrinked .mov files into mpeg2 files via compressor 2 (so that I can made a DVD in DVD SP), the files become corrupt when I use 2-pass vbr. (Frame freezes on play back in DVD SP and QT pro). It's OK with 1 pass vbr though.
    If I convert those huge .mov files via mpeg4 in QT pro rather than h.264, there is not problem with 2-pass vbr.
    So my delemma is: shall I store the files using mpeg4, or h.264?
    I am under the impression that h.264 gives a better quality for the same file size than mpeg4, but 2-pass vbr will give a better quality than 1-pass vbr if I want to burn it on a DVD.
    Thanks in advance.

    In general recompressing from VHS to your computer to H.264 (or MPEG 4) then to m2v is going to hurt quality, so if you are able to get extra Hard Drives and store that way, or even a inexpensive camera with a firewire in/out you are probably better off (though with VHS it may be hard to tell regardless)
    Also if you at least go straight the first time to m2v and check to make sure it looks okay to you, you may want to make sure to do that first
    That being said, H.264 and One-Pass should in all likelihood (I have not tried recently, did it a while ago just to test things) will be better than MPEG-4 2-Pass, depends on the settings. Also if you try 1-Pass H.264 it seems to work with Compressor.

  • Locked file problem with WebDAV

    I am using DreamWeaver CS3 on my Macintosh at home and on a
    PC at work. I am connecting to my website via WebDAV, and for some
    reason Dreamweaver cannot edit the files on the site. When I try to
    check out any file I get an error stating: "file.html is locked and
    can be viewed but not edited" I then have the option to check it
    out or view or cancel. Regardless of what I do, if I continue and
    open the file and make changes the file will not get updated on the
    remote server even though Dreamweaver reports a successful "put" or
    "check in" command in the log file. This happens on both the
    Macintosh and the Windows PC. Both are also updated to the latest
    versions of Dreamweaver.
    The strange thing is, if I mount the WebDAV server as a
    filesystem on my macintosh and authenticate with the same
    login/password that entered in Dreamweaver's WebDAV settings, I can
    edit the html files using a text editor and they save perfectly
    fine. Additionally, while the web server is mounted on the desktop,
    if I change Dreamweaver's site settings to "local/network" and
    enter the locally mounted WebDAV share path instead of using
    Dreamweaver's built-in WebDAV client, then everything works
    properly in Dreamweaver. Reverting back to using WebDAV in
    dreamweaver (as opposed to through the OS) brings about the same
    "locked file" problem as before.
    There appears to be a problem with Dreamweaver's WebDAV
    access to the site, and I'm wondering if there's an easy fix or if
    this has been experienced by others?
    Thanks,
    -Topher

    Have a look at FileUtils::DecomposeUnicode and NormalizeUnComposedUnicodeChars. Use the first to convert before using i.e. FileUtils::PMStringToSysFile() and the later afetr i.e. FileUtils::IDFileToPMString().
    HTH

Maybe you are looking for