I've to translate a Python code to a Java code and I've got a problem with uuencoding.
Python function:
import uu
uu.encode("input_file", "output_file")
Java function:
MimeUtility.encode(new FileOutputStream(output_file_path), "uuencode");
stream.write(Files.readAllBytes(input_file));
The result of these functions should be the same uuencoded file, but it is not (they are almost the same). Java uuencoded file is with 2 bytes bigger than the Python.
Where would the problem be?
Edit:
An extra byte is added after the name tag (<begin><mode><name>
) and a byte after end tag (<end>
)
It is a line break issue.
MIME has always been defined to use CR+LF as terminators, but if using raw encoding such as Python, it is using only LF on Linux. See RFC2045
# https://github.com/python/cpython/blob/2.7/Lib/uu.py
79 out_file.write('begin %o %s\n' % ((mode&0777),name))
You should set the os.linesep
system variable to '\r\n'
so it writes CR+LF line breaks.