• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Utilities类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.notnoop.apns.internal.Utilities的典型用法代码示例。如果您正苦于以下问题:Java Utilities类的具体用法?Java Utilities怎么用?Java Utilities使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Utilities类属于com.notnoop.apns.internal包,在下文中一共展示了Utilities类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: abitComplicatedEnglishLength

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Test
public void abitComplicatedEnglishLength() {
    byte[] dtBytes = new byte[32];
    new Random().nextBytes(dtBytes);

    String deviceToken = Utilities.encodeHex(dtBytes);
    PayloadBuilder builder = new PayloadBuilder().alertBody("test");

    SimpleApnsNotification fromString = new SimpleApnsNotification(deviceToken, builder.build());
    SimpleApnsNotification fromBytes = new SimpleApnsNotification(dtBytes, Utilities.toUTF8Bytes(builder.build()));

    String expected = "{\"aps\":{\"alert\":\"test\"}}";
    int actualPacketLength = 1 + 2 + dtBytes.length + 2 + /* payload length = */ Utilities.toUTF8Bytes(expected).length;
    assertEquals(actualPacketLength, fromString.length());
    assertEquals(actualPacketLength, fromBytes.length());
    assertEquals(expected.length(), fromString.getPayload().length);
    assertArrayEquals(fromString.marshall(), fromBytes.marshall());
    assertFalse(builder.isTooLong());
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:20,代码来源:PayloadBuilderTest.java


示例2: provideApnsService

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Provides
@Singleton
ApnsService provideApnsService(ServletContext context,
    @Flag(FlagName.APNS_CERT_PASSWORD) String password) {
  String ksAlgorithm =
      ((KeyManagerFactory.getDefaultAlgorithm() == null) ? "sunx509" : KeyManagerFactory
          .getDefaultAlgorithm());
  InputStream inputStream;
  if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
    // The app is running on App Engine...
    // inputStream = context.getResourceAsStream("/WEB-INF/ApnsProduction.jks");
    inputStream = context.getResourceAsStream("/WEB-INF/ApnsDevelopment.jks");
  } else {
    inputStream = context.getResourceAsStream("/WEB-INF/ApnsDevelopment.jks");
  }
  SSLContext sslContext = Utilities.newSSLContext(inputStream, password, "JKS", ksAlgorithm);
  return APNS.newService().withSSLContext(sslContext).withSandboxDestination()
      .withNoErrorDetection().build();
}
 
开发者ID:larrytin,项目名称:realtime-server-appengine,代码行数:20,代码来源:RealtimeServletModule.java


示例3: abitComplicatedEnglishLength

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Test
public void abitComplicatedEnglishLength() {
    final byte[] dtBytes = new byte[32];
    new Random().nextBytes(dtBytes);

    final String deviceToken = Utilities.encodeHex(dtBytes);
    final PayloadBuilder builder = new PayloadBuilder().alertBody("test");

    final SimpleApnsNotification fromString = new SimpleApnsNotification(deviceToken, builder.build());
    final SimpleApnsNotification fromBytes = new SimpleApnsNotification(dtBytes, Utilities.toUTF8Bytes(builder.build()));

    final String expected = "{\"aps\":{\"alert\":\"test\"}}";
    final int actualPacketLength = 1 + 2 + dtBytes.length + 2 + /* payload length = */ Utilities.toUTF8Bytes(expected).length;
    assertEquals(actualPacketLength, fromString.length());
    assertEquals(actualPacketLength, fromBytes.length());
    assertEquals(expected.length(), fromString.getPayload().length);
    assertArrayEquals(fromString.marshall(), fromBytes.marshall());
    assertFalse(builder.isTooLong());
}
 
开发者ID:leancloud,项目名称:java-apns,代码行数:20,代码来源:PayloadBuilderTest.java


示例4: ApnsServiceFactory

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
public ApnsServiceFactory() {
    this.gatewayHost = Utilities.PRODUCTION_GATEWAY_HOST;
    this.gatewayPort = Utilities.PRODUCTION_GATEWAY_PORT;

    this.feedbackHost = Utilities.PRODUCTION_FEEDBACK_HOST;
    this.feedbackPort = Utilities.PRODUCTION_FEEDBACK_PORT;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:8,代码来源:ApnsServiceFactory.java


示例5: prepareAndStartServer

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
public static ApnsServerStub prepareAndStartServer(int gatePort, int feedPort) {
    InputStream stream = ClassLoader.getSystemResourceAsStream(FixedCertificates.SERVER_STORE);
    SSLContext context = Utilities.newSSLContext(stream, FixedCertificates.SERVER_PASSWORD, 
                                                 "PKCS12", getAlgorithm());

    
    ApnsServerStub server = new ApnsServerStub(
            context.getServerSocketFactory(),
            gatePort, feedPort);
    server.start();
    return server;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:13,代码来源:ApnsUtils.java


示例6: toString

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Override
public String toString() {
    String payloadString = "???";
    try {
        payloadString = new String(payload, "UTF-8");
    } catch (Exception _) {}        
    return "Message(Token="+Utilities.encodeHex(deviceToken)+"; Payload="+payloadString+")";
}
 
开发者ID:East196,项目名称:maker,代码行数:9,代码来源:SimpleApnsNotification.java


示例7: resizeAlertBody

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
/**
 * Shrinks the alert message body so that the resulting payload
 * message fits within the passed expected payload length.
 *
 * This method performs best-effort approach, and its behavior
 * is unspecified when handling alerts where the payload
 * without body is already longer than the permitted size, or
 * if the break occurs within word.
 *
 * @param payloadLength the expected max size of the payload
 * @param postfix for the truncated body, e.g. "..."
 * @return  this
 */
public PayloadBuilder resizeAlertBody(final int payloadLength, final String postfix) {
    int currLength = length();
    if (currLength <= payloadLength) {
        return this;
    }

    // now we are sure that truncation is required
    String body = (String)customAlert.get("body");

    final int acceptableSize = Utilities.toUTF8Bytes(body).length
            - (currLength - payloadLength
                    + Utilities.toUTF8Bytes(postfix).length);
    body = Utilities.truncateWhenUTF8(body, acceptableSize) + postfix;

    // set it back
    customAlert.put("body", body);

    // calculate the length again
    currLength = length();

    if(currLength > payloadLength) {
        // string is still too long, just remove the body as the body is
        // anyway not the cause OR the postfix might be too long
        customAlert.remove("body");
    }

    return this;
}
 
开发者ID:East196,项目名称:maker,代码行数:42,代码来源:PayloadBuilder.java


示例8: EnhancedApnsNotification

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
/**
 * Constructs an instance of {@code ApnsNotification}.
 *
 * The message encodes the payload with a {@code UTF-8} encoding.
 *
 * @param dtoken    The Hex of the device token of the destination phone
 * @param payload   The payload message to be sent
 */
public EnhancedApnsNotification(
        int identifier, int expiryTime,
        String dtoken, String payload) {
    this.identifier = identifier;
    this.expiry = expiryTime;
    this.deviceToken = Utilities.decodeHex(dtoken);
    this.payload = Utilities.toUTF8Bytes(payload);
}
 
开发者ID:East196,项目名称:maker,代码行数:17,代码来源:EnhancedApnsNotification.java


示例9: marshall

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
/**
 * Returns the binary representation of the message as expected by the
 * APNS server.
 *
 * The returned array can be used to sent directly to the APNS server
 * (on the wire/socket) without any modification.
 */
public byte[] marshall() {
    if (marshall == null) {
        marshall = Utilities.marshallEnhanced(COMMAND, identifier,
                expiry, deviceToken, payload);
    }
    return marshall;
}
 
开发者ID:East196,项目名称:maker,代码行数:15,代码来源:EnhancedApnsNotification.java


示例10: toString

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Override
public String toString() {
    String payloadString = "???";
    try {
        payloadString = new String(payload, "UTF-8");
    } catch (Exception _) {}        
    return "Message(Id="+identifier+"; Token="+Utilities.encodeHex(deviceToken)+"; Payload="+payloadString+")";
}
 
开发者ID:East196,项目名称:maker,代码行数:9,代码来源:EnhancedApnsNotification.java


示例11: messageSendFailed

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Override
  public void messageSendFailed(ApnsNotification message, Throwable e) {
    LOGGER.error("APNS Message delivery failed for key:{}", key, e);
    if (message != null) {
      byte[] tokenByte = message.getDeviceToken();
      String deviceToken = Utilities.encodeHex(tokenByte);
      LOGGER.error("APNS Message delivery failed for key:{}", key, e);

      //TODO : Revisit failure handling. Commented on 12/17/2015
//      invalidateToken(deviceToken);
//      byte[] payload = message.getPayload();
//      String payloadString = fromBytes(payload);
//      if (payloadString != null) {
//        APNSPayloadInfo info = APNSPayloadInfo.parse(payloadString);
//        if (info != null && info.getMessageId() != null) {
//          Integer errorCode = null;
//          if (e instanceof ApnsDeliveryErrorException) {
//            errorCode = Integer.valueOf(((ApnsDeliveryErrorException) e).getDeliveryError().code());
//          }
//          //mark push message state as error
//          updatePushMessageState(info.getMessageId(), errorCode);
//        }
//      }
    } else {
      LOGGER.error("APNS Message delivery failed but ApnsNotification message is null and hence can't invalidate the token");
    }
  }
 
开发者ID:magnetsystems,项目名称:message-server,代码行数:28,代码来源:MMXAPNSDelegate.java


示例12: resizeAlertBody

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
/**
 * Shrinks the alert message body so that the resulting payload
 * message fits within the passed expected payload length.
 *
 * This method performs best-effort approach, and its behavior
 * is unspecified when handling alerts where the payload
 * without body is already longer than the permitted size, or
 * if the break occurs within word.
 *
 * @param payloadLength the expected max size of the payload
 * @param postfix for the truncated body, e.g. "..."
 * @return  this
 */
public PayloadBuilder resizeAlertBody(int payloadLength, String postfix) {
    int currLength = length();
    if (currLength <= payloadLength) {
        return this;
    }

    // now we are sure that truncation is required
    String body = (String)customAlert.get("body");

    int acceptableSize = Utilities.toUTF8Bytes(body).length
            - (currLength - payloadLength
                    + Utilities.toUTF8Bytes(postfix).length);
    body = Utilities.truncateWhenUTF8(body, acceptableSize) + postfix;

    // set it back
    customAlert.put("body", body);

    // calculate the length again
    currLength = length();

    if(currLength > payloadLength) {
        // string is still too long, just remove the body as the body is
        // anyway not the cause OR the postfix might be too long
        customAlert.remove("body");
    }

    return this;
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:42,代码来源:PayloadBuilder.java


示例13: serverContext

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
public static SSLContext serverContext() {
    try {
        System.setProperty("javax.net.ssl.trustStore", ClassLoader.getSystemResource(CLIENT_STORE).getPath());
        InputStream stream = ClassLoader.getSystemResourceAsStream(SERVER_STORE);
        SSLContext context = Utilities.newSSLContext(stream, SERVER_PASSWD, "PKCS12", "sunx509");

        return context;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:12,代码来源:FixedCertificates.java


示例14: clientContext

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
public static SSLContext clientContext() {
    try {
        InputStream stream = ClassLoader.getSystemResourceAsStream(CLIENT_STORE);
        SSLContext context = Utilities.newSSLContext(stream, CLIENT_PASSWD, "PKCS12", "sunx509");
        context.init(null, new TrustManager[] { new X509TrustManagerTrustAll() }, new SecureRandom());
        return context;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:11,代码来源:FixedCertificates.java


示例15: truncateUTF8Properly

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Theory
public void truncateUTF8Properly(Object[] p) {
    String str = (String)p[0];
    int maxBytes = (Integer)p[1];
    int expectedBytes = (Integer)p[2];

    String result = Utilities.truncateWhenUTF8(str, maxBytes);
    byte[] utf8 = Utilities.toUTF8Bytes(result);

    Assert.assertEquals(expectedBytes, utf8.length);
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:12,代码来源:StringTruncationTest.java


示例16: simpleEnglishLength

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Test
public void simpleEnglishLength() {
    PayloadBuilder builder = new PayloadBuilder().alertBody("test");
    String expected = "{\"aps\":{\"alert\":\"test\"}}";
    assertEqualsJson(expected, builder.build());
    int actualLength = Utilities.toUTF8Bytes(expected).length;
    assertEquals(actualLength, builder.length());
    assertFalse(builder.isTooLong());
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:10,代码来源:PayloadBuilderTest.java


示例17: deviceTokenPart

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Theory
public void deviceTokenPart(String deviceToken, PayloadBuilder payload) {
    SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payload.build());
    byte[] bytes = msg.marshall();

    byte[] dt = decodeHex(deviceToken);
    assertEquals(dt.length, /* found length */ (bytes[1] << 8) + bytes[2]);

    // verify the device token part
    assertArrayEquals(dt, Utilities.copyOfRange(bytes, 3, 3 + dt.length));
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:12,代码来源:SimpleApnsNotificationTest.java


示例18: payloadPart

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Theory
public void payloadPart(String deviceToken, PayloadBuilder payload) {
    String payloadString = payload.build();
    SimpleApnsNotification msg = new SimpleApnsNotification(deviceToken, payloadString);
    byte[] bytes = msg.marshall();

    byte[] pl = toUTF8Bytes(payloadString);

    // in reverse
    int plBegin = bytes.length - pl.length;

    /// verify the payload part
    assertArrayEquals(pl, Utilities.copyOfRange(bytes, plBegin, bytes.length));
    assertEquals(pl.length, (bytes[plBegin - 2] << 8) + bytes[plBegin - 1]);
}
 
开发者ID:wangqi,项目名称:gameserver,代码行数:16,代码来源:SimpleApnsNotificationTest.java


示例19: toString

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
@Override
@SuppressFBWarnings("DE_MIGHT_IGNORE")
public String toString() {
    String payloadString;
    try {
        payloadString = new String(payload, "UTF-8");
    } catch (Exception ex) {
        payloadString = "???";
    }
    return "Message(Token="+Utilities.encodeHex(deviceToken)+"; Payload="+payloadString+")";
}
 
开发者ID:dzh,项目名称:jframe,代码行数:12,代码来源:SimpleApnsNotification.java


示例20: marshall

import com.notnoop.apns.internal.Utilities; //导入依赖的package包/类
/**
 * Returns the binary representation of the message as expected by the
 * APNS server.
 *
 * The returned array can be used to sent directly to the APNS server
 * (on the wire/socket) without any modification.
 */
public byte[] marshall() {
    if (marshall == null) {
        marshall = Utilities.marshallEnhanced(COMMAND, identifier,
                expiry, deviceToken, payload);
    }
    return marshall.clone();
}
 
开发者ID:dzh,项目名称:jframe,代码行数:15,代码来源:EnhancedApnsNotification.java



注:本文中的com.notnoop.apns.internal.Utilities类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java KernelServices类代码示例发布时间:2022-05-23
下一篇:
Java RevisionResource类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap