1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
public static byte [] ImageToByte(File file) throws FileNotFoundException{
FileInputStream fis = new FileInputStream(file);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
try {
for (int readNum; (readNum = fis.read(buf)) != -1;) {
bos.write(buf, 0, readNum);
// System.out.println("read " + readNum + " bytes,");
}
} catch (IOException ex) {
ex.printStackTrace();
}
byte[] bytes = bos.toByteArray();
return bytes;
}
public boolean save2Samba(byte[] text, String fileName) {
// jcifs.Config.setProperty("jcifs.netbios.wins", "192.168.1.78");
String username="mcotte";
String password="toto";
String domaine="mondomaine";
Log.d("Password", password);
String url = "smb://" + fileName;
Log.d("Url", url);
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domaine,
username, password);
SmbFile sFile;
try {
sFile = new SmbFile(url, auth);
Log.d("sFile11", sFile.getURL().toString());
Log.d("Can write", ""+sFile.canWrite());
SmbFileOutputStream out = new SmbFileOutputStream( sFile, false);
Log.d("debug","après SMBOS");
for (byte octet : text){
out.write(octet);
}
Log.d("debug","après out.write");
try {
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
} |