Pega uses Base64Utils class to convert the data into the bytearray with the help of encode and decode methods in it. You can look into the Base64Utils class methods and use the appropriate one.
For further information kindly refer SendEmailMessage function where the email attachments are converted into the bytearray. pyAttachStream property is used to capture Attachment stream encoded to Base64. You can write a temp file using this bytearray or stream invoking java.io library. Once the file is created you can use sendFile API to keep it in required directory.