Exemple #1
0
  /**
   * Convert the ImageInfo (renamed ImageData) object into bytes so we can store it in RMS Order of
   * the string will look like this: <recordId>*<foreignRecordId>*<labelName>*<imageLabel> Depending
   * on the optional features, additional fields may be: <phoneNum>
   *
   * @throws InvalidImageDataException
   */
  public byte[] getBytesFromImageInfo(ImageData ii) throws InvalidImageDataException {

    // Take each String and get the bytes from it, separating fields with a
    // delimiter
    try {
      String byteString = new String();

      // Convert the record ID for this record
      int i = ii.getRecordId();
      Integer j = new Integer(i);
      byteString = byteString.concat(j.toString());
      byteString = byteString.concat(DELIMITER);

      // Convert the 'Foreign' Record ID field for the corresponding Image
      // record store
      int i2 = ii.getForeignRecordId();
      Integer j2 = new Integer(i2);
      byteString = byteString.concat(j2.toString());
      byteString = byteString.concat(DELIMITER);

      // Convert the album name field
      byteString = byteString.concat(ii.getParentAlbumName());
      byteString = byteString.concat(DELIMITER);

      // Convert the label (name) field
      byteString = byteString.concat(ii.getImageLabel());

      // Convert the phone number field
      return byteString.getBytes();
    } catch (Exception e) {
      throw new InvalidImageDataException("The provided data are not valid");
    }
  }
Exemple #2
0
  /**
   * Convert the byte array from a retrieved RecordStore record into the ImageInfo ((renamed
   * ImageData) object Order of the string will look like this:
   * <recordId>*<foreignRecordId>*<labelName>*<imageLabel> Depending on the optional features,
   * additional fields may be: <phoneNum>
   *
   * @throws InvalidArrayFormatException
   */
  public ImageData getImageInfoFromBytes(byte[] bytes) throws InvalidArrayFormatException {

    try {
      String iiString = new String(bytes);

      // Track our position in the String using delimiters
      // Ie. Get chars from beginning of String to first Delim
      int startIndex = 0;
      int endIndex = iiString.indexOf(DELIMITER);

      // Get recordID int value as String - everything before first
      // delimeter
      String intString = iiString.substring(startIndex, endIndex);

      // Get 'foreign' record ID corresponding to the image table
      startIndex = endIndex + 1;
      endIndex = iiString.indexOf(DELIMITER, startIndex);
      String fidString = iiString.substring(startIndex, endIndex);

      // Get Album name (recordstore) - next delimeter
      startIndex = endIndex + 1;
      endIndex = iiString.indexOf(DELIMITER, startIndex);
      String albumLabel = iiString.substring(startIndex, endIndex);

      startIndex = endIndex + 1;
      endIndex = iiString.indexOf(DELIMITER, startIndex);

      if (endIndex == -1) endIndex = iiString.length();

      String imageLabel = "";
      imageLabel = iiString.substring(startIndex, endIndex);

      Integer x = Integer.valueOf(fidString);
      ImageData ii = new ImageData(x.intValue(), albumLabel, imageLabel);

      x = Integer.valueOf(intString);
      ii.setRecordId(x.intValue());
      return ii;
    } catch (Exception e) {
      throw new InvalidArrayFormatException();
    }
  }