I get a file then convert it to string and replace some words.
With this string I run the following:
com.hierynomus.smbj.share.File remoteSmbjFile = share.openFile(fileName, EnumSet.of(AccessMask.GENERIC_WRITE), null, s, null, null);
byte[] myFile= template.getBytes("UTF-8");
ByteArrayInputStream bs = new ByteArrayInputStream(myFile);
try (OutputStream outputStream = remoteSmbjFile.getOutputStream();) {
byte[] buffer = new byte[1024];
int length;
while ((length = bs.read(buffer)) > 0) {
outputStream.write(buffer, 0, length);
}
}
The file gets created at a network location and is fine (no problems). The file itself is an .xml type ranging in 2-10 MB in size.
I'm using the xml file type to open this file in word if there is one character off the file will be corrupted.
I'm just worried due to the files size this method will cause a corruption.
Is the above method safe practice are there any other approaches I could take?