putss fiz igualzinhoo
mas acontece uns problemas…
um é quando dá problema falando que a memória do jvm acabou
e o outro é que ele não consegue abrir…
estou trabalhando com um arquivo de 34mb!
outro problema é quando eu tentei usando esse exemplo aqui:
http://www.javafree.org/viewtopic.jbb?t=870556
Nesse ultimo caso ele nao abre…
format error: Not a PDF or corrupted
mas no IE, no Browser do Eclise, e nos outros browser o pdf abre normalmente!!!
alguém conseguiu abrir no browser do firefox???
Sujere alguma coisa? vou postar meu codigo aqui!
vlw!
package br.com.projeto.client;
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletAjuda extends HttpServlet {
private static final int TAMANHO = 34398208;
private byte[] arquivo;
private File file;
public byte[] getArquivo() {
return arquivo;
}
public void setArquivo(byte[] arquivo) {
this.arquivo = arquivo;
}
public File getFile() {
if (file == null) {
file = new File("C:/Libs/HELP.pdf");
}
return file;
}
public void setFile(File file) {
this.file = file;
}
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("application/pdf");
ServletOutputStream ouputStream = response.getOutputStream();
// try {
// setArquivo(fileToByte(getFile()));
// } catch (Exception e) {
// e.printStackTrace();
// }
try {
preparaArquivo(ouputStream, getFile());
} catch (Exception e) {
e.printStackTrace();
}
response.setContentLength(TAMANHO);
response.setHeader("Content-disposition", "attachment;filename=" +getFile().getName());
// ouputStream.write(getArquivo(), 0, getArquivo().length);
ouputStream.flush();
ouputStream.close();
}
public static InputStream byteToInputStream(byte[] bytes) throws Exception {
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
return bais;
}
public static byte[] fileToByte(File file) throws Exception {
FileInputStream fis = new FileInputStream(file);
// int filelength = (int) arquivo.length();
// byte[] buffer = new byte[filelength];
// fis.read(buffer);
// fis.close();
// return buffer;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[34394702];
int bytesRead = 0;
while ((bytesRead = fis.read(buffer, 0, 34394702)) != -1) {
baos.write(buffer, 0, bytesRead);
}
fis.close();
return baos.toByteArray();
}
public void preparaArquivo(ServletOutputStream ouputStream, File file) throws Exception{
// int filelength = (int) file.length();
int tamanho = TAMANHO;
byte buff[] = new byte[tamanho];
FileInputStream fis = new FileInputStream(file);
try{
BufferedInputStream buffer = new BufferedInputStream(fis);
int i;
while((i = buffer.read(buff, 0, tamanho)) != -1){
ouputStream.write(buff, 0, i);
}
buffer.close();
}catch (Exception e) {
e.printStackTrace();
e.getMessage();
e.getCause();
}
}
}
vlw de novo