views:

14

answers:

0

I have an AIDL-accesible service that downloads files via FTP, and uses FTPClient to obtain the file stream. The service obtains the host path and the file path and FTPClient.getFileStream() returns a fileStream for some files I have tested that are around 1MB in size. However for large files, the getFileStream returns null, and THROWS an NULL exception object. Not a NullException object, but an Exception that is null. My phone proceeds to freeze completely and then restart.

The strangest part about it however, is that I have created a separate Android application entirely where I have hard-coded the host and file-path for the same large file and it works fine. This is being executed this time in an activity.

I have verified over and over that the host and path strings match exactly, and cannot for the life of me figure out why the service gets a null, and dies.

Here is the code for the working Activity:

String userName="anonymous";
  String passWord = "[email protected]";
  String ftpAddress = "173.192.225.183";
  String retrieveFromFTPFolder = "/2/PSX-PAL/";
  String strLine;
  DataInputStream inputStream = null;
  BufferedReader bufferedReader = null;
  FTPClient client = null;
  FTPFile[] ftpFiles = null;
  int reply;

  try{

      client = new FTPClient();
   client.setListHiddenFiles(true);
   //FTPClientConfig conf = new FTPClientConfig(FTPClientConfig.SYST_UNIX);
   //client.configure(conf);
   client.connect(ftpAddress);
   client.login(userName, passWord);
   client.setFileType(FTP.BINARY_FILE_TYPE);
   //ftpFiles = client.listFiles(retrieveFromFTPFolder);  //retrieve list of files from ftp server

    InputStream myFileStream = client.retrieveFileStream("/2/PSX-PAL/Metal Gear Solid (Demo) (E) [SLED-01400].7z");
      inputStream = new DataInputStream(myFileStream);
      bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
      //save file from ftp to local directory
      File fileToWrite = new File("/sdcard/Metal Gear Solid (Demo) (E) [SLED-01400].7z");
      java.io.FileOutputStream fos = new java.io.FileOutputStream(fileToWrite);
      java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);
      byte data[] = new byte[1024];
      int x = 0;
      while((x=myFileStream.read(data,0,1024))>=0){
          bout.write(data,0,x);
      }
      bout.close();
      myFileStream.close();
      // Must call completePendingCommand() to finish command.
      if(!client.completePendingCommand()) {
          client.logout();
          client.disconnect();
          System.err.println("File transfer failed.");
      }

Here is the code for the mysterious server:

 String userName="anonymous";
              String passWord = "[email protected]";

            Pattern p = Pattern.compile("ftp://(.+?)(/.+/(.+))");
            Matcher m = p.matcher(completePathToFile);
            m.find();

              String hostPart = m.group(1);
              String pathExcludingHostIncludingFirstSlash= m.group(2);
              fileName = URLDecoder.decode(m.group(3));


                String tempFileForZip = Environment.getExternalStorageDirectory().getAbsolutePath() + GlobalVars.getSaveLocation(context, searchResult.getConsole()) + fileName;
                boolean mkdirresult = (new File(tempFileForZip)).getParentFile().mkdirs();
                FileOutputStream fos = new FileOutputStream(new File(tempFileForZip));
                java.io.BufferedOutputStream bout = new BufferedOutputStream(fos,1024);

                   FTPclient = new FTPClient();
                   FTPclient.setListHiddenFiles(true);
                   FTPclient.connect(hostPart);
                   boolean loggedIn = FTPclient.login(userName, passWord);
                   FTPclient.setFileType(FTP.BINARY_FILE_TYPE);


                    InputStream myFileStream = FTPclient.retrieveFileStream(URLDecoder.decode(pathExcludingHostIncludingFirstSlash));
                    DataInputStream instream = new DataInputStream(myFileStream);