开发者

heap size warning when uploading a file using url connection

开发者 https://www.devze.com 2023-02-09 20:18 出处:网络
i am trying to upload a file to Amazon S3 using HttpUrlConn开发者_StackOverflow中文版ection and the put method.

i am trying to upload a file to Amazon S3 using HttpUrlConn开发者_StackOverflow中文版ection and the put method.

  outputStream = new DataOutputStream( connection.getOutputStream() );
        bytesAvailable = fileInputStream.available();
        int current = 0;
        bufferSize = Math.min(bytesAvailable, maxBufferSize);
        buffer = new byte[bufferSize];

        // Read file
        bytesRead = fileInputStream.read(buffer, 0, bufferSize);

        while (bytesRead > 0)
       {
            outputStream.write(buffer, 0, bufferSize);
            bytesAvailable = fileInputStream.available();
            bufferSize = Math.min(bytesAvailable, maxBufferSize);
            bytesRead = fileInputStream.read(buffer, 0, bufferSize);
            current+=bytesRead;
        }

is this the proper way to use the buffer to output data? It all works great for smaller files but when i try to upload something larger it says

02-11 19:04:38.718: INFO/dalvikvm-heap(15385): Grow heap (frag case) to 9.204MB for 3143696-byte allocation

what am i doing wrong? any help is highly appreciated, thank you.

0

精彩评论

暂无评论...
验证码 换一张
取 消