Andoird file upload buffer issue

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Andoird file upload buffer issue

Postby kchandu5200 » Sat Nov 17, 2012 11:09 am

Hi
I am trying to uploading a file using below code.
But I am getting this “I/global(476): Default buffer size used in BufferedReader constructor. It would be better to be explicit if an 8k-char buffer is required.” But file was uploading while testing in PC. when I install in mobile that time the file not uploading and the app was automatically closed.

FTPClient ftpClient = new FTPClient();

ftpClient.connect(InetAddress.getByName(SERVER));
ftpClient.login(USERNAME, PASSWORD);
ftpClient.changeWorkingDirectory("/xxx");
//
System.out.println(ftpClient.isConnected() + " Check Connection");
try
{
ftpClient.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
BufferedInputStream buffIn = null;
buffIn = new BufferedInputStream(new FileInputStream(strFile));
ftpClient.enterLocalPassiveMode();
Handler progressHandler = new Handler();
ProgressInputStream progressInput = new ProgressInputStream(buffIn, progressHandler);

boolean result = ftpClient.storeFile(fileName, progressInput);
buffIn.close();
ftpClient.logout();
ftpClient.disconnect();

}
catch(Exception e)
{
}




package com.example.sendmail;

import java.io.IOException;
import java.io.InputStream;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;

public class ProgressInputStream extends InputStream {

/* Key to retrieve progress value from message bundle passed to handler */
public static final String PROGRESS_UPDATE = "progress_update";

private static final int TEN_KILOBYTES = 1024 * 10;

private InputStream inputStream;
private Handler handler;

private long progress;
private long lastUpdate;

private boolean closed;

public ProgressInputStream(InputStream inputStream, Handler handler) {
this.inputStream = inputStream;
this.handler = handler;

this.progress = 0;
this.lastUpdate = 0;

this.closed = false;
}

@Override
public int read() throws IOException {
int count = inputStream.read();
return incrementCounterAndUpdateDisplay(count);
}

@Override
public int read(byte[] b, int off, int len) throws IOException {
int count = inputStream.read(b, off, len);
return incrementCounterAndUpdateDisplay(count);
}

@Override
public void close() throws IOException {
super.close();
if (closed)
throw new IOException("already closed");
closed = true;
}

private int incrementCounterAndUpdateDisplay(int count) {
if (count > 0)
progress += count;
lastUpdate = maybeUpdateDisplay(progress, lastUpdate);
return count;
}

private long maybeUpdateDisplay(long progress, long lastUpdate) {
if (progress - lastUpdate > TEN_KILOBYTES) {
lastUpdate = progress;
sendLong(PROGRESS_UPDATE, progress);
}
return lastUpdate;
}

public void sendLong(String key, long value) {
Bundle data = new Bundle();
data.putLong(key, value);

Message message = Message.obtain();
message.setData(data);
handler.sendMessage(message);
}
}


Thanks,
Chandu
kchandu5200
Once Poster
Once Poster
 
Posts: 1
Joined: Sat Nov 17, 2012 9:40 am

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 3 guests