Ante todo diculpas por saltarme la norma del idioma.
Me he revisado el historico de mails de
archives.java.sun.com/archives/servlet-interest.html
y quedo sorprendido que nadie haya planteado este problema.
Llevo muchos dias, muchas horas tras una solucion y descubro en JDC que
posiblemente se trate de un bug:
(http://developer.java.sun.com/developer/bugParade/bugs/4212479.html), que
dice asi:
Data(o Buffered)OutputStream from a URLConnection does not flush writes.
Desde el browser el envio de ficheros grandes no da problemas.(Me pregunto
qu� tecnica usan los navegadores que no puede reproducirse en Java).
La alternativa que se me plantea es enviar bloques peque�os de datos en cada
petici�n y mediante un intercambio de confirmaciones modificar la recepcion
para que los datos se a�adan al mismo fichero (lo que no deja de ser un
tanto chapucero).
Sugerencias, opiniones, noticias... seran recibidas como agua de mayo.
Torondel.
(Gedas)
----------------------------------------------------------------
Original English version:
I need to send files from Java Client application to servlet.
The code work fine but when the length of file is too big I get
OutOfMemoryError.
How can I to solve this problem.
Thanks in advance,
Torondel
-----------------
My sample code:
File target = new File("MyFile");
try {
HttpURLConnection connection = (HttpURLConnection)
url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setUseCaches(false);
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "
application/octet-stream");
connection.setRequestProperty("Content-Length", " " +
target.length());
}
catch (Exception e) {}
try {
destination = new
BufferedOutputStream(connection.getOutputStream(),8*1024);
source = new BufferedInputStream(new FileInputStream( target ));
buffer = new byte[100 * 1024];
while(true) {
bytes_read = source.read(buffer,0, buffer.length);
if (bytes_read == -1) break;
destination.write(buffer, 0, bytes_read);
}
destination.flush();
}
finally {
if (source != null)
try { source.close(); } catch (IOException e) { ; }
if (destination != null)
try { destination.close(); } catch (IOException e) { ; }
}
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html