dimanche 28 juin 2015

Exception on sendig big files through java sockets

Well im creating a Chat in java for a university project, and one of the requirements is each user must have an image associate, this can be done through registration windows and data modification windows, in registration everything works great, but on the modification window, the program throws an exception when i try to send big files, both codes (registration and modification) are basiccally the same, changing only variables and path, but still gives my problem only in modification

Here is my code:


BufferedImage image = ImageIO.read(new    File(usuario.getImagen().getCanonicalPath()));
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", byteArrayOutputStream);
byte[] size = ByteBuffer.allocate(4).putInt(byteArrayOutputStream.size()).array();


dir = new File ("." + "/Documentos/Imagenes de Verificacion/" +
                    usuarioRegistro.getNombreDeUsuario() + ".jpg");
sizeAr = new byte[4];
size = ByteBuffer.wrap(sizeAr).asIntBuffer().get();
imageAr = new byte[size];
image = ImageIO.read(new ByteArrayInputStream(imageAr));
ImageIO.write(image, "jpg", new File(dir.getCanonicalPath()));

And the exception is:

Exception in thread "Thread-0" java.lang.IllegalArgumentException: image == null!
at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925)
at javax.imageio.ImageIO.getWriter(ImageIO.java:1591)
at javax.imageio.ImageIO.write(ImageIO.java:1520)
at com.ucab.javachat.Servidor.model.ServidorModel.run(ServidorModel.java:198)

The line ServiorModel.java:198 is: ImageIO.write(image, "jpg", new File(dir.getCanonicalPath()));

In my tests i can send images of 20, 30, 80, 200 Kb, but when i try to send the 2.1mb file gives the error.

Any other information you need just ask!

Thanks in advance for any help you can provide, sorry for the bad english

Aucun commentaire:

Enregistrer un commentaire