Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5971087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:28:04+00:00 2026-05-22T20:28:04+00:00

First off, this is the error I am getting java.lang.OutOfMemoryError at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56) at coderaustin.com.Main.onCreate(Main.java:41)

  • 0

First off, this is the error I am getting

   java.lang.OutOfMemoryError
at coderaustin.com.FileEncryptor.encryptFile(FileEncryptor.java:56)
at coderaustin.com.Main.onCreate(Main.java:41)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
at dalvik.system.NativeStart.main(Native Method)

Obviously I know what the error is, I just don’t know how to avoid it. This is what my app does,

You select a file, and click Encrypt. So obviously from there it takes the file, and encrypts it using this code

try {
    FileInputStream inFile = new FileInputStream(f.getAbsolutePath());
    FileOutputStream outFile = new FileOutputStream(f.getAbsoluteFile() + ".des");

    PBEKeySpec keySpec = new PBEKeySpec(text.toCharArray());
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey passwordKey = keyFactory.generateSecret(keySpec);
    byte[] salt = new byte[8];
    Random rnd = new Random();
    rnd.nextBytes(salt);
    int iterations = 100;

    PBEParameterSpec paramaterSpec = new PBEParameterSpec(salt, iterations);

    Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
    cipher.init(Cipher.ENCRYPT_MODE, passwordKey, paramaterSpec);

    outFile.write(salt);



    byte[] input = new byte[inFile.available()];

    int bytesRead;
     while ((bytesRead = inFile.read(input)) != -1)
                {
                  byte[] output = cipher.update(input, 0, bytesRead);
                   if (output != null) outFile.write(output);
               }

               byte[] output = cipher.doFinal();
               if (output != null) outFile.write(output);
               f.delete();
              inFile.close();
               outFile.flush();
               outFile.close();

Yes I know the code is pretty ugly, but it works. Any suggestions?

Thanks all 🙂

Edit: This is line 56

byte[] input = new byte[inFile.available()];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:28:04+00:00Added an answer on May 22, 2026 at 8:28 pm

    Odd: if the file is very big I could see how that could be an issue. Why are you reading the entire file at once instead of reading it in small chunks and processing?

    EDIT: try this.

    byte[] input = new byte[4096];
    
        int bytesRead;
         while ((bytesRead = inFile.read(input, 0, 4096)) != -1)
                    {
                      byte[] output = cipher.update(input, 0, bytesRead);
                       if (output != null) outFile.write(output);
                   }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off, this question is ripped out from this question. I did it because
First off, I apologize if this doesn't make sense. I'm new to XHTML, CSS
First off, let me preface this question by stating that I'm really a pretty
First off, there's a bit of background to this issue available on my blog:
Any idea why this error is happening and how to fix it? I'm getting
First off, I am not dynamically creating any controls. This is the order I
First off, I am using Windows XP. I have multiple hard drives and it
First off, I understand the reasons why an interface or abstract class (in the
First off if you're unaware, samba or smb == Windows file sharing, \\computer\share etc.
First off: I'm using a rather obscure implementation of javascript embedded as a scripting

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.