SearchObject.java :  » Network » smartphone-networks » com » mobed » musishan » Android Open Source

Android Open Source » Network » smartphone networks 
smartphone networks » com » mobed » musishan » SearchObject.java
package com.mobed.musishan;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.io.StreamCorruptedException;
import java.util.Arrays;
import java.util.Date;

@SuppressWarnings("serial")
public class SearchObject implements Serializable {
  private String     search_keyword;
  private String    search_deadline;
  private boolean[]   search_options = new boolean[3];
  
  public SearchObject () {
    this.clear();
  }
  
  public SearchObject (String keyword, String deadline, boolean options[]) {
    this.search_keyword = keyword;
    this.search_deadline = deadline;
    this.search_options = options;  
  }
  
  public void setSearchKeyword (String key) {
    this.search_keyword = key;
  }
  
  public String getSearchKeyword () {
    return this.search_keyword;
  }
  
  public void setSearchDeadline (String deadline) {
    this.search_deadline = deadline;
  }
  
  public void setSearchDeadline (Date deadline) {
    this.search_deadline = deadline.toString();
  }
  
  public String getSearchDeadline () {
    return this.search_deadline;
  }
  
  public boolean [] getSearchOptions() {
    return this.search_options;
  }
  
  public String toString() {
    return "Keyword: " + search_keyword+ "\nOptions: " +  search_options[0] +"," + search_options[1]+ "," + search_options[2] + "\nDeadline: " + search_deadline;
  }
  
  public byte[] getByte() throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
      ObjectOutputStream oos = new ObjectOutputStream(bos); 
    
      oos.writeObject(this);
      
    oos.flush();
    oos.close();
    bos.close();
          
      return bos.toByteArray(); 
  }
  
  public void setByte(byte[] _input) throws StreamCorruptedException, IOException, ClassNotFoundException {
    ByteArrayInputStream bis = new ByteArrayInputStream(_input);
    ObjectInputStream ois = new ObjectInputStream(bis);
  
    SearchObject obj =  (SearchObject)ois.readObject();
  
    this.search_options = obj.getSearchOptions();
    this.search_keyword = obj.getSearchKeyword();
    this.search_deadline = obj.getSearchDeadline();
    
    ois.close();
    bis.close();
  }
  
  public void clear() {
    this.search_deadline = null;
    this.search_keyword = null;
    Arrays.fill(this.search_options, false);
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.