Ver Mensaje Individual
  #3 (permalink)  
Antiguo 08/05/2012, 11:51
Avatar de Hollman
Hollman
 
Fecha de Ingreso: enero-2003
Ubicación: Bogotá - Colombia
Mensajes: 202
Antigüedad: 21 años, 2 meses
Puntos: 1
Sonrisa Respuesta: byte[] to Object[]

Muchas gracias por responder Fuzzylog.

Acá tenemos un inconveniente... el archivoEnBytes es el contenido (bytes[]) de un archivo PDF. Cuando intento hacer lo sugerido me sale el error invalid stream header: 25504446.

Alguna otra sugerencia.. Hay un par de constructores... cuando se manda un String (que es la ruta obtenida del fileChooser y ejecutarlo bien) y la otra es enviando los byte[] de un archivo (PDF)... esto segundo es que no me anda.



Para emular el envío de los byte[] utilizo lo obtenido de la siguiente función....

Código:
public static byte[] getBytesFromFile(File file) throws IOException {
        InputStream is = new FileInputStream(file);

        // Get the size of the file
        long length = file.length();

        if (length > Integer.MAX_VALUE) {
            // File is too large
            return null;
        }

        // Create the byte array to hold the data
        byte[] bytes = new byte[(int) length];

        // debug - init array
        for (int i = 0; i < length; i++) {
            bytes[i] = 0x0;
        }

        // Read in the bytes
        int offset = 0;
        int numRead = 0;
        while (offset < bytes.length && (numRead = is.read(bytes, offset, bytes.length - offset)) >= 0) {
            offset += numRead;
        }

        // Ensure all the bytes have been read in
        if (offset < bytes.length) {
            throw new IOException("Could not completely read file " + file.getName());
        }

        // Close the input stream and return bytes
        is.close();
        return bytes;
    }

Última edición por Hollman; 08/05/2012 a las 11:56 Razón: complementar respuesta