Package net.sf.jpluck.plucker

Source Code of net.sf.jpluck.plucker.MailtoRecord

package net.sf.jpluck.plucker;

import net.sf.jpluck.palm.PdbOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class MailtoRecord extends LinkableRecord {
  private String to;
  private String cc;
  private String subject;
  private String body;

  public MailtoRecord(String uri, String to) {
    super(uri);
    this.to = to;
  }

  public String getTo() {
    return to;
  }

  public String getCc() {
    return cc;
  }

  public void setCc(String cc) {
    this.cc = cc;
  }

  public String getSubject() {
    return subject;
  }

  public void setSubject(String subject) {
    this.subject = subject;
  }

  public String getBody() {
    return body;
  }

  public void setBody(String body) {
    this.body = body;
  }

  public Paragraph[] writeData(PdbOutputStream out) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PdbOutputStream pdb = new PdbOutputStream(baos);
    int offset = 8;
    if (to != null) {
      pdb.writeShort(offset);
      offset += to.length() + 1;
    } else {
      pdb.writeShort(0);
    }
    if (cc != null) {
      pdb.writeShort(offset);
      offset += cc.length() + 1;
    } else {
      pdb.writeShort(0);
    }
    if (subject != null) {
      pdb.writeShort(offset);
      offset += subject.length() + 1;
    } else {
      pdb.writeShort(0);
    }
    if (body != null) {
      pdb.writeShort(offset);
      offset += body.length() + 1;
    } else {
      pdb.writeShort(0);
    }
    if (to != null) {
      pdb.writeString(to);
      pdb.writeByte(0);
    }
    if (cc != null) {
      pdb.writeString(cc);
      pdb.writeByte(0);
    }
    if (subject != null) {
      pdb.writeString(subject);
      pdb.writeByte(0);
    }
    if (body != null) {
      pdb.writeString(body);
      pdb.writeByte(0);
    }

    byte[] data = baos.toByteArray();
    out.write(data);
    return null;
  }

  protected int getType() {
    return DataRecord.MAILTO;
  }
}
TOP

Related Classes of net.sf.jpluck.plucker.MailtoRecord

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.