Citation :
public class testUpload
{
public static void main(String [] args){
String devis = "devis";
String nomFichier = "kldjklzejf" +
"sdkfgdlmfjgomdfijgfd" +
"gdfgikpdofigpodfigopidfg" +
"gpdfgpofdkpgoidfpogifd" +
"mdfgjkdpfoigoidfgoçuero";
byte[] buf =new byte[1024];
InputStream stream = new ByteArrayInputStream(nomFichier.getBytes());
try
{
FileHttp.put("http://pluton/recette/", stream, devis);
} catch (IOException e)
{
throw new RuntimeException(e);
}
} }
public class FileHttp
{
public final static String EXT_XML = ".xml";
public final static String EXT_PDF = ".pdf";
public static void put(String repDefaut, InputStream is, String nomFichier) throws IOException {
URL url = new URL(repDefaut + nomFichier);
HttpURLConnection connect =(HttpURLConnection)url.openConnection();
connect.setRequestMethod("PUT" );
connect.setDoOutput(true);
connect.setRequestProperty("ContentType", "text/xml" );
OutputStream os = connect.getOutputStream();
byte[] buf =new byte[1024];
int c;
while((c = is.read(buf)) > -1)
os.write(buf, 0, c);
LogManager.getInstance().log("Connecting to " + url.toString(),LogManager.INFORMATION);
connect.connect();
BufferedReader bis = new BufferedReader(new InputStreamReader(connect.getInputStream()));
String line;
while((line = bis.readLine()) !=null)
LogManager.getInstance().log(line,LogManager.INFORMATION);
os.close();
bis.close();
connect.disconnect();
}
}
|