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

Java CGlobal类代码示例

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

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



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

示例1: _getPeriodText

import com.helger.commons.CGlobal; //导入依赖的package包/类
private static String _getPeriodText (@Nonnull final LocalDateTime aNowLDT, @Nonnull final LocalDateTime aNotAfter)
{
  final Period aPeriod = Period.between (aNowLDT.toLocalDate (), aNotAfter.toLocalDate ());
  final Duration aDuration = Duration.between (aNowLDT.toLocalTime (),
                                               aNotAfter.plus (1, ChronoUnit.DAYS).toLocalTime ());

  long nSecs = aDuration.getSeconds ();
  final long nHours = nSecs / CGlobal.SECONDS_PER_HOUR;
  nSecs -= nHours * CGlobal.SECONDS_PER_HOUR;
  final long nMinutes = nSecs / CGlobal.SECONDS_PER_MINUTE;
  nSecs -= nMinutes * CGlobal.SECONDS_PER_MINUTE;
  return aPeriod.getYears () +
         " years, " +
         aPeriod.getMonths () +
         " months, " +
         aPeriod.getDays () +
         " days, " +
         nHours +
         " hours, " +
         nMinutes +
         " minutes and " +
         nSecs +
         " seconds";
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:25,代码来源:PDCommonUI.java


示例2: _timedSearch

import com.helger.commons.CGlobal; //导入依赖的package包/类
private static void _timedSearch (@Nonnull final IThrowingRunnable <IOException> aRunnable,
                                  @Nonnull final Query aQuery) throws IOException
{
  final StopWatch aSW = StopWatch.createdStarted ();
  try
  {
    aRunnable.run ();
  }
  finally
  {
    final long nMillis = aSW.stopAndGetMillis ();
    s_aStatsQueryTimer.addTime (aQuery.toString (), nMillis);
    if (nMillis > CGlobal.MILLISECONDS_PER_SECOND)
      s_aLogger.warn ("Lucene Query " + aQuery + " took too long: " + nMillis + "ms");
  }
}
 
开发者ID:phax,项目名称:peppol-directory,代码行数:17,代码来源:PDStorageManager.java


示例3: getNodeAsBytes

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Convert the passed DOM node to an XML byte array using the provided XML
 * writer settings.
 *
 * @param aNode
 *        The node to be converted to a byte array. May not be
 *        <code>null</code>.
 * @param aSettings
 *        The XML writer settings to be used. May not be <code>null</code>.
 * @return The byte array representation of the passed node.
 * @since 8.6.3
 */
@Nullable
public static byte [] getNodeAsBytes (@Nonnull final Node aNode, @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aSettings, "Settings");

  try (final NonBlockingByteArrayOutputStream aWriter = new NonBlockingByteArrayOutputStream (50 *
                                                                                              CGlobal.BYTES_PER_KILOBYTE))
  {
    // start serializing
    if (writeToStream (aNode, aWriter, aSettings).isSuccess ())
      return aWriter.toByteArray ();
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error serializing DOM node with settings " + aSettings.toString (), t);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:32,代码来源:XMLWriter.java


示例4: getNodeAsString

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Convert the passed micro node to an XML string using the provided settings.
 *
 * @param aNode
 *        The node to be converted to a string. May not be <code>null</code> .
 * @param aSettings
 *        The XML writer settings to use. May not be <code>null</code>.
 * @return The string representation of the passed node.
 */
@Nullable
public static String getNodeAsString (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aSettings, "Settings");

  try (final NonBlockingStringWriter aWriter = new NonBlockingStringWriter (50 * CGlobal.BYTES_PER_KILOBYTE))
  {
    // start serializing
    if (writeToWriter (aNode, aWriter, aSettings).isSuccess ())
      return aWriter.getAsString ();
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:MicroWriter.java


示例5: getNodeAsBytes

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Convert the passed micro node to an XML byte array using the provided
 * settings.
 *
 * @param aNode
 *        The node to be converted to a byte array. May not be
 *        <code>null</code> .
 * @param aSettings
 *        The XML writer settings to use. May not be <code>null</code>.
 * @return The byte array representation of the passed node.
 * @since 8.6.3
 */
@Nullable
public static byte [] getNodeAsBytes (@Nonnull final IMicroNode aNode, @Nonnull final IXMLWriterSettings aSettings)
{
  ValueEnforcer.notNull (aNode, "Node");
  ValueEnforcer.notNull (aSettings, "Settings");

  try (final NonBlockingByteArrayOutputStream aBAOS = new NonBlockingByteArrayOutputStream (50 *
                                                                                            CGlobal.BYTES_PER_KILOBYTE))
  {
    // start serializing
    if (writeToStream (aNode, aBAOS, aSettings).isSuccess ())
      return aBAOS.toByteArray ();
  }
  catch (final Throwable t)
  {
    s_aLogger.error ("Error serializing MicroDOM with settings " + aSettings.toString (), t);
  }
  return null;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:32,代码来源:MicroWriter.java


示例6: generateKey

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Nonnull
public static SecretKey generateKey ()
{
  final int nKeyLengthBytes = CryptoPolicy.isUnlimitedStrengthCryptoAvailable () ? 32 : 16;
  try
  {
    // Use JCA
    final KeyGenerator aKeyGen = KeyGenerator.getInstance ("AES");
    aKeyGen.init (nKeyLengthBytes * CGlobal.BITS_PER_BYTE);
    return aKeyGen.generateKey ();
  }
  catch (final GeneralSecurityException ex)
  {
    // Why so ever - create an AES key on our own!
    final byte [] aBytes = new byte [nKeyLengthBytes];
    RandomHelper.getRandom ().nextBytes (aBytes);
    return new AESSecretKey (aBytes);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:20,代码来源:AESCryptFuncTest.java


示例7: testGetChildTextContentWithConversionAndNS

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testGetChildTextContentWithConversionAndNS ()
{
  final String sNSURI = "my-namespace-uri";
  final IMicroElement e = new MicroElement (sNSURI, "x");
  assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  final IMicroElement y = e.appendElement (sNSURI, "y");
  assertNull (MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendText ("100");
  assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendElement ("a");
  assertEquals (CGlobal.BIGINT_100, MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
  y.appendCDATA ("234");
  assertEquals (BigInteger.valueOf (100234),
                MicroHelper.getChildTextContentWithConversion (e, sNSURI, "y", BigInteger.class));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:17,代码来源:MicroHelperTest.java


示例8: CombinationGenerator

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Ctor
 *
 * @param aElements
 *        the elements to fill into the slots for creating all combinations
 *        (must not be empty!)
 * @param nSlotCount
 *        the number of slots to use (must not be greater than the element
 *        count!)
 */
public CombinationGenerator (@Nonnull @Nonempty final ICommonsList <DATATYPE> aElements,
                             @Nonnegative final int nSlotCount)
{
  ValueEnforcer.notEmpty (aElements, "Elements");
  ValueEnforcer.isBetweenInclusive (nSlotCount, "SlotCount", 0, aElements.size ());

  m_aElements = GenericReflection.uncheckedCast (aElements.toArray ());
  m_aIndexResult = new int [nSlotCount];
  final BigInteger aElementFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length);
  final BigInteger aSlotFactorial = FactorialHelper.getAnyFactorialLinear (nSlotCount);
  final BigInteger aOverflowFactorial = FactorialHelper.getAnyFactorialLinear (m_aElements.length - nSlotCount);
  m_aTotalCombinations = aElementFactorial.divide (aSlotFactorial.multiply (aOverflowFactorial));
  // Can we use the fallback to long? Is much faster than using BigInteger
  m_bUseLong = m_aTotalCombinations.compareTo (CGlobal.BIGINT_MAX_LONG) < 0;
  m_nTotalCombinations = m_bUseLong ? m_aTotalCombinations.longValue () : CGlobal.ILLEGAL_ULONG;
  reset ();
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:28,代码来源:CombinationGenerator.java


示例9: getWithoutPath

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Get the name of the passed file without any eventually leading path.
 *
 * @param sAbsoluteFilename
 *        The fully qualified file name. May be <code>null</code>.
 * @return The name only or <code>null</code> if the passed parameter is
 *         <code>null</code>.
 * @see #getIndexOfLastSeparator(String)
 */
@Nullable
public static String getWithoutPath (@Nullable final String sAbsoluteFilename)
{
  /**
   * Note: do not use <code>new File (sFilename).getName ()</code> since this
   * only invokes the underlying FileSystem implementation which handles path
   * handling only correctly on the native platform. Problem arose when
   * running application on a Linux server and making a file upload from a
   * Windows machine.
   */
  if (sAbsoluteFilename == null)
    return null;
  final int nLastSepIndex = getIndexOfLastSeparator (sAbsoluteFilename);
  return nLastSepIndex == CGlobal.ILLEGAL_UINT ? sAbsoluteFilename : sAbsoluteFilename.substring (nLastSepIndex + 1);
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:25,代码来源:FilenameHelper.java


示例10: enableSoapLogging

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Enable the JAX-WS SOAP debugging. This shows the exchanged SOAP messages in
 * the log file. By default this logging is disabled.
 *
 * @param bServerDebug
 *        <code>true</code> to enable server debugging, <code>false</code> to
 *        disable it.
 * @param bClientDebug
 *        <code>true</code> to enable client debugging, <code>false</code> to
 *        disable it.
 */
public static void enableSoapLogging (final boolean bServerDebug, final boolean bClientDebug)
{
  // Server debug mode
  String sDebug = Boolean.toString (bServerDebug);
  SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.client.HttpTransportPipe.dump", sDebug);
  SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.dump", sDebug);

  // Client debug mode
  sDebug = Boolean.toString (bClientDebug);
  SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.HttpTransportPipe.dump", sDebug);
  SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.HttpTransportPipe.dump", sDebug);

  // Enlarge dump size
  if (bServerDebug || bClientDebug)
  {
    final String sValue = Integer.toString (2 * CGlobal.BYTES_PER_MEGABYTE);
    SystemProperties.setPropertyValue ("com.sun.xml.ws.transport.http.HttpAdapter.dumpTreshold", sValue);
    SystemProperties.setPropertyValue ("com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold", sValue);
  }
  else
  {
    SystemProperties.removePropertyValue ("com.sun.xml.ws.transport.http.HttpAdapter.dumpTreshold");
    SystemProperties.removePropertyValue ("com.sun.xml.internal.ws.transport.http.HttpAdapter.dumpTreshold");
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:37,代码来源:WSHelper.java


示例11: testGetAsTB

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Test method getAsTB
 */
@Test
public void testGetAsTB ()
{
  // Use fixed locale for constant decimal separator
  final SizeHelper aSH = SizeHelper.getSizeHelperOfLocale (Locale.ENGLISH);

  // default
  assertEquals ("0TB", aSH.getAsTB (0));
  assertEquals ("5TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE));

  // with decimals
  assertEquals ("0.00TB", aSH.getAsTB (0, 2));
  assertEquals ("5TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 0));
  assertEquals ("5.0TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 1));
  assertEquals ("5.00TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 2));
  assertEquals ("5.000TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 3));
  assertEquals ("5.0000TB", aSH.getAsTB (5 * CGlobal.BYTES_PER_TERABYTE, 4));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:SizeHelperTest.java


示例12: getExtractedIntValue

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Extract the int representation of the passed bit set. To avoid loss of
 * data, the bit set may not have more than 32 bits.
 *
 * @param aBS
 *        The bit set to extract the value from. May not be <code>null</code>.
 * @return The extracted value. May be negative if the bit set has 32
 *         elements, the highest order bit is set.
 */
public static int getExtractedIntValue (@Nonnull final BitSet aBS)
{
  ValueEnforcer.notNull (aBS, "BitSet");

  final int nMax = aBS.length ();
  ValueEnforcer.isTrue (nMax <= CGlobal.BITS_PER_INT,
                        () -> "Can extract only up to " + CGlobal.BITS_PER_INT + " bits");

  int ret = 0;
  for (int i = nMax - 1; i >= 0; --i)
  {
    ret <<= 1;
    if (aBS.get (i))
      ret += CGlobal.BIT_SET;
  }
  return ret;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:BitSetHelper.java


示例13: getExtractedLongValue

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Extract the long representation of the passed bit set. To avoid loss of
 * data, the bit set may not have more than 64 bits.
 *
 * @param aBS
 *        The bit set to extract the value from. May not be <code>null</code>.
 * @return The extracted value. May be negative if the bit set has 64
 *         elements, the highest order bit is set.
 */
public static long getExtractedLongValue (@Nonnull final BitSet aBS)
{
  ValueEnforcer.notNull (aBS, "BitSet");

  final int nMax = aBS.length ();
  ValueEnforcer.isTrue (nMax <= CGlobal.BITS_PER_LONG,
                        () -> "Can extract only up to " + CGlobal.BITS_PER_LONG + " bits");

  long ret = 0;
  for (int i = nMax - 1; i >= 0; --i)
  {
    ret <<= 1;
    if (aBS.get (i))
      ret += CGlobal.BIT_SET;
  }
  return ret;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:27,代码来源:BitSetHelper.java


示例14: testAll

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testAll ()
{
  for (final EProcessorArchitecture e : EProcessorArchitecture.values ())
  {
    assertSame (e, EProcessorArchitecture.valueOf (e.name ()));
    assertSame (e, EProcessorArchitecture.forBits (e.getBits ()));
  }

  final EProcessorArchitecture eArch = EProcessorArchitecture.getCurrentArchitecture ();
  assertNotNull (eArch);
  assertTrue (eArch.getBits () > 0);
  assertTrue (eArch.getBytes () > 0);

  if (EJVMVendor.getCurrentVendor ().isSun ())
  {
    // For Sun JVMs the architecture must be determined!
    assertNotSame (eArch, EProcessorArchitecture.UNKNOWN);
  }
  assertEquals (CGlobal.ILLEGAL_UINT, EProcessorArchitecture.UNKNOWN.getBytes ());
  assertEquals (CGlobal.ILLEGAL_UINT, EProcessorArchitecture.UNKNOWN.getBits ());
  assertSame (EProcessorArchitecture.UNKNOWN, EProcessorArchitecture.forBits (1));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:24,代码来源:EProcessorArchitectureTest.java


示例15: testGetWithoutTrailingZeroes

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testGetWithoutTrailingZeroes ()
{
  assertNull (MathHelper.getWithoutTrailingZeroes ((String) null));
  assertNull (MathHelper.getWithoutTrailingZeroes ((BigDecimal) null));

  assertEquals (BigDecimal.ZERO, MathHelper.getWithoutTrailingZeroes (BigDecimal.ZERO));
  assertEquals (BigDecimal.ONE, MathHelper.getWithoutTrailingZeroes (BigDecimal.ONE));
  assertEquals (BigDecimal.TEN, MathHelper.getWithoutTrailingZeroes (BigDecimal.TEN));
  assertEquals (BigDecimal.ONE, MathHelper.getWithoutTrailingZeroes ("1.0000"));
  assertEquals (CGlobal.BIGDEC_100, MathHelper.getWithoutTrailingZeroes ("100.000"));
  assertEquals (new BigDecimal ("100.01"), MathHelper.getWithoutTrailingZeroes ("100.0100"));
  assertEquals (new BigDecimal ("600"), MathHelper.getWithoutTrailingZeroes ("6e2"));
  assertEquals (new BigDecimal ("0.1"), MathHelper.getWithoutTrailingZeroes ("0.1000"));
  assertEquals (new BigDecimal ("0.001"), MathHelper.getWithoutTrailingZeroes ("0.001000"));
  assertEquals (BigDecimal.ZERO, MathHelper.getWithoutTrailingZeroes ("0.00000"));
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:18,代码来源:MathHelperTest.java


示例16: testAll

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testAll ()
{
  final StatisticsHandlerKeyedCounter sh = new StatisticsHandlerKeyedCounter ();
  assertEquals (0, sh.getInvocationCount ());
  assertEquals (CGlobal.ILLEGAL_ULONG, sh.getCount ("key1"));
  assertEquals (CGlobal.ILLEGAL_ULONG, sh.getCount ("key2"));
  sh.increment ("key1");
  assertEquals (1, sh.getInvocationCount ());
  assertEquals (1L, sh.getCount ("key1"));
  assertEquals (CGlobal.ILLEGAL_ULONG, sh.getCount ("key2"));
  sh.increment ("key1", 2);
  assertEquals (2, sh.getInvocationCount ());
  assertEquals (3L, sh.getCount ("key1"));
  assertEquals (CGlobal.ILLEGAL_ULONG, sh.getCount ("key2"));
  sh.increment ("key2");
  assertEquals (3, sh.getInvocationCount ());
  assertEquals (3L, sh.getCount ("key1"));
  assertEquals (1L, sh.getCount ("key2"));
  assertEquals (2, sh.getAllKeys ().size ());
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:StatisticsHandlerKeyedCounterTest.java


示例17: testParseBigDecimal

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Test
public void testParseBigDecimal ()
{
  final BigDecimal aBD1M = StringParser.parseBigDecimal ("1000000");
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1.000.000", L_DE, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", L_EN, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", (DecimalFormat) NumberFormat.getInstance (L_EN)));
  assertEquals (new BigDecimal ("1234567.8901"),
                LocaleParser.parseBigDecimal ("1.234.567,8901", L_DE, CGlobal.BIGDEC_MINUS_ONE));
  assertEquals (CGlobal.BIGDEC_MINUS_ONE,
                LocaleParser.parseBigDecimal ("... und denken", L_EN, CGlobal.BIGDEC_MINUS_ONE));
  final ChoiceFormat aCF = new ChoiceFormat ("-1#negative|0#zero|1.0#one");
  assertEquals (BigDecimal.valueOf (0.0), LocaleParser.parseBigDecimal ("zero", aCF, CGlobal.BIGDEC_MINUS_ONE));

  try
  {
    LocaleParser.parseBigDecimal ("0", (DecimalFormat) null);
    fail ();
  }
  catch (final NullPointerException ex)
  {}
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:LocaleParserTest.java


示例18: getInputStream

import com.helger.commons.CGlobal; //导入依赖的package包/类
@Nullable
public static InputStream getInputStream (@Nonnull final File aFile)
{
  ValueEnforcer.notNull (aFile, "File");

  final FileInputStream aFIS = FileHelper.getInputStream (aFile);
  if (aFIS != null)
  {
    // Check if using a memory mapped file makes sense (file size > 1MB)
    final FileChannel aChannel = aFIS.getChannel ();
    if (getFileSize (aChannel) > CGlobal.BYTES_PER_MEGABYTE)
    {
      // Check if mapping is possible
      final InputStream aIS = _getMappedInputStream (aChannel, aFile);
      if (aIS != null)
        return aIS;

      // Mapping failed - fall through
    }
  }
  return aFIS;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:23,代码来源:FileChannelHelper.java


示例19: pbkdf2

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Computes the PBKDF2 hash of a password.
 *
 * @param aPassword
 *        the password to hash.
 * @param aSalt
 *        the salt
 * @param nIterations
 *        the iteration count (slowness factor)
 * @param nBytes
 *        the length of the hash to compute in bytes
 * @return the PBDKF2 hash of the password
 */
@Nonnull
protected static final byte [] pbkdf2 (@Nonnull final char [] aPassword,
                                       @Nonnull final byte [] aSalt,
                                       @Nonnegative final int nIterations,
                                       @Nonnegative final int nBytes)
{
  try
  {
    final PBEKeySpec spec = new PBEKeySpec (aPassword, aSalt, nIterations, nBytes * CGlobal.BITS_PER_BYTE);
    final SecretKeyFactory skf = SecretKeyFactory.getInstance (PBKDF2_ALGORITHM);
    return skf.generateSecret (spec).getEncoded ();
  }
  catch (final GeneralSecurityException ex)
  {
    throw new IllegalStateException ("Failed to apply PBKDF2 algorithm", ex);
  }
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:31,代码来源:AbstractPasswordHashCreatorPBKDF2.java


示例20: _createCert

import com.helger.commons.CGlobal; //导入依赖的package包/类
/**
 * Create a new dummy certificate based on the passed key pair
 *
 * @param kp
 *        KeyPair to use. May not be <code>null</code>.
 * @return A {@link X509Certificate} for further usage
 */
@Nonnull
private X509Certificate _createCert (@Nonnull final KeyPair kp) throws Exception
{
  final PublicKey aPublicKey = kp.getPublic ();
  final PrivateKey aPrivateKey = kp.getPrivate ();
  final ContentSigner aContentSigner = new JcaContentSignerBuilder ("SHA1withRSA").setProvider (BouncyCastleProvider.PROVIDER_NAME)
                                                                                  .build (aPrivateKey);

  // Form yesterday
  final Date aStartDate = new Date (System.currentTimeMillis () - 24 * CGlobal.MILLISECONDS_PER_HOUR);
  // For one year from now
  final Date aEndDate = new Date (System.currentTimeMillis () + 365 * 24 * CGlobal.MILLISECONDS_PER_HOUR);

  final X509v1CertificateBuilder aCertBuilder = new JcaX509v1CertificateBuilder (new X500Principal ("CN=TestIssuer"),
                                                                                 BigInteger.ONE,
                                                                                 aStartDate,
                                                                                 aEndDate,
                                                                                 new X500Principal ("CN=TestSubject"),
                                                                                 aPublicKey);
  final X509CertificateHolder aCertHolder = aCertBuilder.build (aContentSigner);
  // Convert to JCA X509Certificate
  return new JcaX509CertificateConverter ().getCertificate (aCertHolder);
}
 
开发者ID:phax,项目名称:ph-xmldsig,代码行数:31,代码来源:XMLDSigCreatorTest.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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