Exemple #1
0
 private void closeConnection() {
   try {
     socket.close();
     in.close();
     out64.close();
   } catch (Exception e) {
   }
 }
Exemple #2
0
  /**
   * Send file as attachment encoded in Base64, and returns true if file was successfully and
   * completely transferred.
   */
  private void sendAttachment(AbstractFile file) throws IOException {
    InputStream fileIn = null;
    try {
      // Send MIME type of attachment file
      String mimeType = MimeTypes.getMimeType(file);
      // Default mime type
      if (mimeType == null) mimeType = "application/octet-stream";
      writeLine("Content-Type:" + mimeType + "; name=" + file.getName());
      writeLine("Content-Disposition: attachment;filename=\"" + file.getName() + "\"");
      writeLine("Content-transfer-encoding: base64\r\n");
      fileIn = setCurrentInputStream(file.getInputStream());

      // Write file to socket
      StreamUtils.copyStream(fileIn, out64);

      // Writes padding bytes without closing the stream.
      out64.writePadding();

      writeLine("\r\n--" + boundary);
    } finally {
      if (fileIn != null) fileIn.close();
    }
  }