Package org.nfctools.ndef

Examples of org.nfctools.ndef.NdefEncoderException


  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {
    GcTargetRecord gcTargetRecord = (GcTargetRecord)wellKnownRecord;
    if (!gcTargetRecord.hasTargetIdentifier()) {
      throw new NdefEncoderException(wellKnownRecord.getClass().getSimpleName()
          + " must have target identifier", wellKnownRecord);
    }
    return messageEncoder.encodeSingle(gcTargetRecord.getTargetIdentifier());
  }
View Full Code Here


    StringBuilder result = new StringBuilder();

    // if coordinates, then no address information and the opposite.
    if(geoRecord.hasCoordinates()) {
      if(geoRecord.hasAddressInformation()) {
        throw new NdefEncoderException("Expected latitude and longitude coordinates or address information, not both.", externalType);
      }
     
      Double latitude = geoRecord.getLatitude();
      if (latitude.doubleValue() > 90.0 || latitude.doubleValue() < -90.0) {
        throw new NdefEncoderException("Expected latitude within 90 positive or negative degrees, found " + latitude + " degrees.", externalType);
      }
      Double longitude = geoRecord.getLongitude();
      if (longitude.doubleValue() > 180.0 || longitude.doubleValue() < -180.0) {
        throw new NdefEncoderException("Expected longitude within 180 positive or negative degrees, found " + longitude + " degrees.", externalType);
      }

      result.append(latitude.toString());
      result.append(',');
      result.append(longitude.toString());
    else if(geoRecord.hasLatitude()) {
      throw new NdefEncoderException("Expected longitude coordinate set when latitude coordinate set.", externalType);
    else if(geoRecord.hasLongitude()) {
      throw new NdefEncoderException("Expected latitude coordinate set when longitude coordinate set.", externalType);
    } else if(!geoRecord.hasAddressInformation()) {
      throw new NdefEncoderException("Expected coordinates or address information set.", externalType);
    } else {
      result.append("0,0");
    }

    if (geoRecord.hasAltitude()) {
View Full Code Here

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
     
      baos.write(myRecord.getConfigurationByte());

      if(!myRecord.hasTarget()) {
        throw new NdefEncoderException("Expected target", myRecord);
      }
      baos.write(messageEncoder.encodeSingle(myRecord.getTarget()));

      if (myRecord.getAction() != null)
        baos.write(messageEncoder.encodeSingle(myRecord.getAction()));
View Full Code Here

  public String encodeContent(ExternalTypeRecord externalType) {
   
    AndroidApplicationRecord androidApplicationRecord = (AndroidApplicationRecord)externalType;
   
    if(!androidApplicationRecord.hasPackageName()) {
      throw new NdefEncoderException("Expected package name ", androidApplicationRecord);
    }

    return androidApplicationRecord.getPackageName();
  }
View Full Code Here

     
    } else if(externalType instanceof UnsupportedExternalTypeRecord){
      UnsupportedExternalTypeRecord externalTypeUnsupportedRecord = (UnsupportedExternalTypeRecord)externalType;
     
      if(!externalTypeUnsupportedRecord.hasContent()) {
        throw new NdefEncoderException("Expected content", record);
      }
      if(!externalTypeUnsupportedRecord.hasNamespace()) {
        throw new NdefEncoderException("Expected namespace", record);
      }

      namespace = externalTypeUnsupportedRecord.getNamespace();
      payload = externalTypeUnsupportedRecord.getContent().getBytes(NdefConstants.DEFAULT_CHARSET);
    } else {
      throw new NdefEncoderException("Unable to encode external type " + externalType.getClass().getName(), record);
    }
   
    byte[] type = namespace.getBytes(NdefConstants.DEFAULT_CHARSET);
    return new NdefRecord(NdefConstants.TNF_EXTERNAL_TYPE, type, record.getId(), payload);
  }
View Full Code Here

        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        baos.write(signatureRecord.getVersion());

        if(!signatureRecord.hasSignatureType()) {
          throw new NdefEncoderException("Expected signature type", signatureRecord);
        }

        if(signatureRecord.hasSignature() && signatureRecord.hasSignatureUri()) {
          throw new NdefEncoderException("Expected signature or signature uri, not both", signatureRecord);
        } else if(!signatureRecord.hasSignature() && !signatureRecord.hasSignatureUri()) {
          throw new NdefEncoderException("Expected signature or signature uri", signatureRecord);
        }

        baos.write(((signatureRecord.hasSignatureUri() ? 1 : 0) << 7) | (signatureRecord.getSignatureType().getValue() & 0x7F));

        byte[] signatureOrUri;
        if(signatureRecord.hasSignature()) {
          signatureOrUri = signatureRecord.getSignature();

          if(signatureOrUri.length > 65535) {
            throw new NdefEncoderException("Expected signature size " + signatureOrUri.length + " <= 65535", signatureRecord);
          }
        } else {
          signatureOrUri = signatureRecord.getSignatureUri().getBytes(NdefConstants.UTF_8_CHARSET);

          if(signatureOrUri.length > 65535) {
            throw new NdefEncoderException("Expected signature uri byte size " + signatureOrUri.length + " <= 65535", signatureRecord);
          }
        }

        baos.write((signatureOrUri.length >> 8) & 0xFF);
        baos.write(signatureOrUri.length & 0xFF);

        baos.write(signatureOrUri);

        if(!signatureRecord.hasCertificateFormat()) {
          throw new NdefEncoderException("Expected certificate format", signatureRecord);
        }

        List<byte[]> certificates = signatureRecord.getCertificates();
        if(certificates.size() > 16) {
          throw new NdefEncoderException("Expected number of certificates " + certificates.size() + " <= 15", signatureRecord);
        }

        CertificateFormat certificateFormat = signatureRecord.getCertificateFormat();
        baos.write(((signatureRecord.hasCertificateUri() ? 1 : 0) << 7) | (certificateFormat.getValue() << 4) | (certificates.size() & 0xF));

        for(int i = 0; i < certificates.size(); i++) {
          byte[] certificate = certificates.get(i);

          if(certificate.length > 65535) {
            throw new NdefEncoderException("Expected certificate " + i + " size " + certificate.length + " <= 65535", signatureRecord);
          }

          baos.write((certificate.length >> 8) & 0xFF);
          baos.write(certificate.length & 0xFF);
          baos.write(certificate);
        }

        if(signatureRecord.hasCertificateUri()) {

          byte[] certificateUri = signatureRecord.getCertificateUri().getBytes(NdefConstants.UTF_8_CHARSET);

          if(certificateUri.length > 65535) {
            throw new NdefEncoderException("Expected certificate uri byte size " + certificateUri.length + " <= 65535", signatureRecord);
          }

          baos.write((certificateUri.length >> 8) & 0xFF);
          baos.write(certificateUri.length & 0xFF);
          baos.write(certificateUri);
View Full Code Here

  @Override
  public byte[] encodePayload(WellKnownRecord wellKnownRecord, NdefMessageEncoder messageEncoder) {
    ActionRecord record = (ActionRecord)wellKnownRecord;
    if (!record.hasAction()) {
      throw new NdefEncoderException("Expected action", wellKnownRecord);
    }
    return new byte[] { record.getAction().getValue() };
  }
View Full Code Here

TOP

Related Classes of org.nfctools.ndef.NdefEncoderException

Copyright © 2018 www.massapicom. 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.