Example usage for org.apache.commons.lang3 RandomStringUtils randomAlphanumeric

List of usage examples for org.apache.commons.lang3 RandomStringUtils randomAlphanumeric

Introduction

In this page you can find the example usage for org.apache.commons.lang3 RandomStringUtils randomAlphanumeric.

Prototype

public static String randomAlphanumeric(final int count) 

Source Link

Document

Creates a random string whose length is the number of characters specified.

Characters will be chosen from the set of alpha-numeric characters.

Usage

From source file:com.tonygalati.sprites.SpriteGenerator.java

public static void main(String[] args) throws IOException {

    //        if (args.length != 3)
    //        {//from ww  w  .j a v  a  2 s  .  co  m
    //           System.out.print("Usage: com.tonygalati.sprites.SpriteGenerator {path to images} {margin between images in px} {output file}\n");
    //           System.out.print("Note: The max height should only be around 32,767px due to Microsoft GDI using a 16bit signed integer to store dimensions\n");
    //           System.out.print("going beyond this dimension is possible with this tool but the generated sprite image will not work correctly with\n");
    //           System.out.print("most browsers.\n\n");
    //           return;
    //        }

    //        Integer margin = Integer.parseInt(args[1]);
    Integer margin = Integer.parseInt("1");
    String spriteFile = "icons-" + RandomStringUtils.randomAlphanumeric(10) + ".png";
    SpriteCSSGenerator cssGenerator = new SpriteCSSGenerator();

    ClassLoader classLoader = SpriteGenerator.class.getClassLoader();
    URL folderPath = classLoader.getResource(NAIC_SMALL_ICON);
    if (folderPath != null) {
        File imageFolder = new File(folderPath.getPath());

        // Read images
        ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();
        Integer yCoordinate = null;

        for (File f : imageFolder.listFiles()) {
            if (f.isFile()) {
                String fileName = f.getName();
                String ext = fileName.substring(fileName.lastIndexOf(".") + 1, fileName.length());

                if (ext.equals("png")) {
                    System.out.println("adding file " + fileName);
                    BufferedImage image = ImageIO.read(f);
                    imageList.add(image);

                    if (yCoordinate == null) {
                        yCoordinate = 0;
                    } else {
                        yCoordinate += (image.getHeight() + margin);
                    }

                    // add to cssGenerator
                    cssGenerator.addSpriteCSS(fileName.substring(0, fileName.indexOf(".")), 0, yCoordinate);
                }
            }
        }

        // Find max width and total height
        int maxWidth = 0;
        int totalHeight = 0;

        for (BufferedImage image : imageList) {
            totalHeight += image.getHeight() + margin;

            if (image.getWidth() > maxWidth)
                maxWidth = image.getWidth();
        }

        System.out.format("Number of images: %s, total height: %spx, width: %spx%n", imageList.size(),
                totalHeight, maxWidth);

        // Create the actual sprite
        BufferedImage sprite = new BufferedImage(maxWidth, totalHeight, BufferedImage.TYPE_INT_ARGB);

        int currentY = 0;
        Graphics g = sprite.getGraphics();
        for (BufferedImage image : imageList) {
            g.drawImage(image, 0, currentY, null);
            currentY += image.getHeight() + margin;
        }

        System.out.format("Writing sprite: %s%n", spriteFile);
        ImageIO.write(sprite, "png", new File(spriteFile));
        File cssFile = cssGenerator.getFile(spriteFile);
        System.out.println(cssFile.getAbsolutePath() + " created");
    } else {
        System.err.println("Could not find folder: " + NAIC_SMALL_ICON);

    }

}

From source file:com.github.liyp.test.TestMain.java

@SuppressWarnings("unchecked")
public static void main(String[] args) {
    // add a shutdown hook to stop the server
    Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
        @Override//from w w  w  .j av  a2s  . c o  m
        public void run() {
            System.out.println("########### shoutdown begin....");
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("########### shoutdown end....");
        }
    }));

    System.out.println(args.length);
    Iterator<String> iterator1 = IteratorUtils
            .arrayIterator(new String[] { "one", "two", "three", "11", "22", "AB" });
    Iterator<String> iterator2 = IteratorUtils.arrayIterator(new String[] { "a", "b", "c", "33", "ab", "aB" });

    Iterator<String> chainedIter = IteratorUtils.chainedIterator(iterator1, iterator2);

    System.out.println("==================");

    Iterator<String> iter = IteratorUtils.filteredIterator(chainedIter, new Predicate() {
        @Override
        public boolean evaluate(Object arg0) {
            System.out.println("xx:" + arg0.toString());
            String str = (String) arg0;
            return str.matches("([a-z]|[A-Z]){2}");
        }
    });
    while (iter.hasNext()) {
        System.out.println(iter.next());
    }

    System.out.println("===================");

    System.out.println("asas".matches("[a-z]{4}"));

    System.out.println("Y".equals(null));

    System.out.println(String.format("%02d", 1000L));

    System.out.println(ArrayUtils.toString(splitAndTrim(" 11, 21,12 ,", ",")));

    System.out.println(new ArrayList<String>().toString());

    JSONObject json = new JSONObject("{\"keynull\":null}");
    json.put("bool", false);
    json.put("keya", "as");
    json.put("key2", 2212222222222222222L);
    System.out.println(json);
    System.out.println(json.get("keynull").equals(null));

    String a = String.format("{\"id\":%d,\"method\":\"testCrossSync\"," + "\"circle\":%d},\"isEnd\":true", 1,
            1);
    System.out.println(a.getBytes().length);

    System.out.println(new String[] { "a", "b" });

    System.out.println(new JSONArray("[\"aa\",\"\"]"));

    String data = String.format("%9d %s", 1, RandomStringUtils.randomAlphanumeric(10));
    System.out.println(data.getBytes().length);

    System.out.println(ArrayUtils.toString("1|2| 3|  333||| 3".split("\\|")));

    JSONObject j1 = new JSONObject("{\"a\":\"11111\"}");
    JSONObject j2 = new JSONObject(j1.toString());
    j2.put("b", "22222");
    System.out.println(j1 + " | " + j2);

    System.out.println("======================");

    String regex = "\\d+(\\-\\d+){2} \\d+(:\\d+){2}";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher("2015-12-28 15:46:14  _NC250_MD:motion de\n");
    String eventDate = matcher.find() ? matcher.group() : "";

    System.out.println(eventDate);
}

From source file:com.labs64.netlicensing.demo.NetLicensingClientDemo.java

public static void main(final String[] args) {

    // configure J.U.L. to Slf4j bridge for Jersey
    SLF4JBridgeHandler.removeHandlersForRootLogger();
    SLF4JBridgeHandler.install();//from w  ww  .j  a  va 2  s . c  o m

    final Context context = new Context();
    context.setBaseUrl("https://go.netlicensing.io/core/v2/rest");
    context.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION);
    context.setUsername("demo");
    context.setPassword("demo");

    final String randomNumber = RandomStringUtils.randomAlphanumeric(8);
    final String productNumber = numberWithPrefix("P", randomNumber);
    final String productModuleNumber = numberWithPrefix("PM", randomNumber);
    final String licenseTemplateNumber = numberWithPrefix("LT", randomNumber);
    final String licenseeNumber = numberWithPrefix("L", randomNumber);
    final String licenseNumber = numberWithPrefix("LC", randomNumber);
    final String licenseeName = numberWithPrefix("Licensee ", RandomStringUtils.randomAlphanumeric(8));

    final ConsoleWriter out = new ConsoleWriter();

    int exitCode = CODE_OK;
    try {

        // region ********* Lists

        final Page<String> licenseTypes = UtilityService.listLicenseTypes(context);
        out.writePage("License Types:", licenseTypes);

        final Page<String> licensingModels = UtilityService.listLicensingModels(context);
        out.writePage("Licensing Models:", licensingModels);

        final Page<Country> countries = UtilityService.listCountries(context, null);
        out.writePage("Countries:", countries);

        // endregion

        // region ********* Product

        final Product newProduct = new ProductImpl();
        newProduct.setNumber(productNumber);
        newProduct.setName("Demo product");
        Product product = ProductService.create(context, newProduct);
        out.writeObject("Added product:", product);

        product = ProductService.get(context, productNumber);
        out.writeObject("Got product:", product);

        Page<Product> products = ProductService.list(context, null);
        out.writePage("Got the following products:", products);

        final Product updateProduct = new ProductImpl();
        updateProduct.addProperty("Updated property name", "Updated value");
        updateProduct.addProperty(Constants.Product.PROP_LICENSEE_SECRET_MODE,
                LicenseeSecretMode.PREDEFINED.toString());
        product = ProductService.update(context, productNumber, updateProduct);
        out.writeObject("Updated product:", product);

        ProductService.delete(context, productNumber, true);
        out.writeMessage("Deleted Product!");

        products = ProductService.list(context, null);
        out.writePage("Got the following Products:", products);

        product = ProductService.create(context, newProduct);
        out.writeObject("Added product again:", product);

        products = ProductService.list(context, null);
        out.writePage("Got the following Products:", products);

        // endregion

        // region ********* ProductModule

        final ProductModule newProductModule = new ProductModuleImpl();
        newProductModule.setNumber(productModuleNumber);
        newProductModule.setName("Demo product module");
        newProductModule.setLicensingModel(Constants.LicensingModel.TryAndBuy.NAME);
        ProductModule productModule = ProductModuleService.create(context, productNumber, newProductModule);
        out.writeObject("Added product module:", productModule);

        productModule = ProductModuleService.get(context, productModuleNumber);
        out.writeObject("Got product module:", productModule);

        Page<ProductModule> productModules = ProductModuleService.list(context, null);
        out.writePage("Got the following product modules:", productModules);

        final ProductModule updateProductModule = new ProductModuleImpl();
        updateProductModule.addProperty("Updated property name", "Updated property value");
        productModule = ProductModuleService.update(context, productModuleNumber, updateProductModule);
        out.writeObject("Updated product module:", productModule);

        ProductModuleService.delete(context, productModuleNumber, true);
        out.writeMessage("Deleted product module!");

        productModules = ProductModuleService.list(context, null);
        out.writePage("Got the following product modules:", productModules);

        productModule = ProductModuleService.create(context, productNumber, newProductModule);
        out.writeObject("Added product module again:", productModule);

        productModules = ProductModuleService.list(context, null);
        out.writePage("Got the following product modules:", productModules);

        // endregion

        // region ********* LicenseTemplate

        final LicenseTemplate newLicenseTemplate = new LicenseTemplateImpl();
        newLicenseTemplate.setNumber(licenseTemplateNumber);
        newLicenseTemplate.setName("Demo Evaluation Period");
        newLicenseTemplate.setLicenseType(LicenseType.FEATURE);
        newLicenseTemplate.setPrice(new BigDecimal(12.5));
        newLicenseTemplate.setCurrency(Currency.EUR);
        newLicenseTemplate.setAutomatic(false);
        newLicenseTemplate.setHidden(false);
        out.writeObject("Adding license template:", newLicenseTemplate);
        LicenseTemplate licenseTemplate = LicenseTemplateService.create(context, productModuleNumber,
                newLicenseTemplate);
        out.writeObject("Added license template:", licenseTemplate);

        licenseTemplate = LicenseTemplateService.get(context, licenseTemplateNumber);
        out.writeObject("Got licenseTemplate:", licenseTemplate);

        Page<LicenseTemplate> licenseTemplates = LicenseTemplateService.list(context, null);
        out.writePage("Got the following license templates:", licenseTemplates);

        final LicenseTemplate updateLicenseTemplate = new LicenseTemplateImpl();
        updateLicenseTemplate.addProperty("Updated property name", "Updated value");
        licenseTemplate = LicenseTemplateService.update(context, licenseTemplateNumber, updateLicenseTemplate);
        out.writeObject("Updated license template:", licenseTemplate);

        LicenseTemplateService.delete(context, licenseTemplateNumber, true);
        out.writeMessage("Deleted license template!");

        licenseTemplates = LicenseTemplateService.list(context, null);
        out.writePage("Got the following license templates:", licenseTemplates);

        licenseTemplate = LicenseTemplateService.create(context, productModuleNumber, newLicenseTemplate);
        out.writeObject("Added license template again:", licenseTemplate);

        licenseTemplates = LicenseTemplateService.list(context, null);
        out.writePage("Got the following license templates:", licenseTemplates);

        // endregion

        // region ********* Licensee

        final Licensee newLicensee = new LicenseeImpl();
        newLicensee.setNumber(licenseeNumber);
        Licensee licensee = LicenseeService.create(context, productNumber, newLicensee);
        out.writeObject("Added licensee:", licensee);

        Page<Licensee> licensees = LicenseeService.list(context, null);
        out.writePage("Got the following licensees:", licensees);

        LicenseeService.delete(context, licenseeNumber, true);
        out.writeMessage("Deleted licensee!");

        licensees = LicenseeService.list(context, null);
        out.writePage("Got the following licensees after delete:", licensees);

        licensee = LicenseeService.create(context, productNumber, newLicensee);
        out.writeObject("Added licensee again:", licensee);

        licensee = LicenseeService.get(context, licenseeNumber);
        out.writeObject("Got licensee:", licensee);

        final Licensee updateLicensee = new LicenseeImpl();
        updateLicensee.addProperty("Updated property name", "Updated value");
        updateLicensee.addProperty(Constants.Licensee.PROP_LICENSEE_SECRET, randomLicenseeSecret);

        licensee = LicenseeService.update(context, licenseeNumber, updateLicensee);
        out.writeObject("Updated licensee:", licensee);

        licensees = LicenseeService.list(context, null);
        out.writePage("Got the following licensees:", licensees);

        // endregion

        // region ********* License

        final License newLicense = new LicenseImpl();
        newLicense.setNumber(licenseNumber);
        License license = LicenseService.create(context, licenseeNumber, licenseTemplateNumber, null,
                newLicense);
        out.writeObject("Added license:", license);

        Page<License> licenses = LicenseService.list(context, null);
        out.writePage("Got the following licenses:", licenses);

        LicenseService.delete(context, licenseNumber, true);
        out.writeMessage("Deleted license!");

        licenses = LicenseService.list(context, null);
        out.writePage("Got the following licenses:", licenses);

        license = LicenseService.create(context, licenseeNumber, licenseTemplateNumber, null, newLicense);
        out.writeObject("Added license again:", license);

        license = LicenseService.get(context, licenseNumber);
        out.writeObject("Got license:", license);

        final License updateLicense = new LicenseImpl();
        updateLicense.addProperty("Updated property name", "Updated value");
        license = LicenseService.update(context, licenseNumber, null, updateLicense);
        out.writeObject("Updated license:", license);

        // endregion

        // region ********* PaymentMethod

        final Page<PaymentMethod> paymentMethods = PaymentMethodService.list(context, null);
        out.writePage("Got the following payment methods:", paymentMethods);

        // endregion

        // region ********* Token

        final Token newToken = new TokenImpl();
        newToken.setTokenType(TokenType.APIKEY);
        final Token apiKey = TokenService.create(context, newToken);
        out.writeObject("Created APIKey:", apiKey);

        context.setApiKey(apiKey.getNumber());
        newToken.setTokenType(TokenType.SHOP);
        newToken.addProperty(Constants.Licensee.LICENSEE_NUMBER, licenseeNumber);
        context.setSecurityMode(SecurityMode.APIKEY_IDENTIFICATION);
        final Token shopToken = TokenService.create(context, newToken);
        context.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION);
        out.writeObject("Got the following shop token:", shopToken);

        final String filter = Constants.Token.TOKEN_TYPE + "=" + TokenType.SHOP.name();
        Page<Token> tokens = TokenService.list(context, filter);
        out.writePage("Got the following shop tokens:", tokens);

        TokenService.delete(context, shopToken.getNumber());
        out.writeMessage("Deleted shop token!");

        tokens = TokenService.list(context, filter);
        out.writePage("Got the following shop tokens after delete:", tokens);

        // endregion

        // region ********* Validate

        final ValidationParameters validationParameters = new ValidationParameters();
        validationParameters.put(productModuleNumber, "paramKey", "paramValue");
        validationParameters.setLicenseeSecret(randomLicenseeSecret);
        validationParameters.setLicenseeName(licenseeName);
        validationParameters.setProductNumber(productNumber);
        ValidationResult validationResult = LicenseeService.validate(context, licenseeNumber,
                validationParameters);
        out.writeObject("Validation result for created licensee:", validationResult);

        context.setSecurityMode(SecurityMode.APIKEY_IDENTIFICATION);
        validationResult = LicenseeService.validate(context, licenseeNumber, validationParameters);
        context.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION);
        out.writeObject("Validation repeated with APIKey:", validationResult);

        // endregion

        // region ********* Transfer
        Licensee transferLicensee = new LicenseeImpl();
        transferLicensee.setNumber("TR" + licenseeNumber);
        transferLicensee.getProperties().put(Constants.Licensee.PROP_MARKED_FOR_TRANSFER,
                Boolean.toString(true));
        transferLicensee = LicenseeService.create(context, productNumber, transferLicensee);
        out.writeObject("Added transfer licensee:", transferLicensee);

        final License transferLicense = new LicenseImpl();
        transferLicense.setNumber("LTR" + licenseNumber);
        final License newTransferLicense = LicenseService.create(context, transferLicensee.getNumber(),
                licenseTemplateNumber, null, transferLicense);
        out.writeObject("Added license for transfer:", newTransferLicense);

        LicenseeService.transfer(context, licensee.getNumber(), transferLicensee.getNumber());

        licenses = LicenseService.list(context, "licenseeNumber=" + licensee.getNumber());
        out.writePage("Got the following licenses after transfer:", licenses);

        Licensee transferLicenseeWithApiKey = new LicenseeImpl();
        transferLicenseeWithApiKey.setNumber("Key" + licenseeNumber);
        transferLicenseeWithApiKey.getProperties().put(Constants.Licensee.PROP_MARKED_FOR_TRANSFER,
                Boolean.toString(true));
        transferLicenseeWithApiKey = LicenseeService.create(context, productNumber, transferLicenseeWithApiKey);

        final License transferLicenseWithApiKey = new LicenseImpl();
        transferLicenseWithApiKey.setNumber("Key" + licenseNumber);
        LicenseService.create(context, transferLicenseeWithApiKey.getNumber(), licenseTemplateNumber, null,
                transferLicenseWithApiKey);

        context.setSecurityMode(SecurityMode.APIKEY_IDENTIFICATION);
        LicenseeService.transfer(context, licensee.getNumber(), transferLicenseeWithApiKey.getNumber());
        context.setSecurityMode(SecurityMode.BASIC_AUTHENTICATION);

        licenses = LicenseService.list(context, "licenseeNumber=" + licensee.getNumber());
        out.writePage("Got the following licenses after transfer:", licenses);
        // endregion

        // region ********* Transactions
        Page<Transaction> transactions = TransactionService.list(context,
                Constants.Transaction.SOURCE_SHOP_ONLY + "=" + Boolean.TRUE.toString());
        out.writePage("Got the following transactions shop only:", transactions);

        transactions = TransactionService.list(context, null);
        out.writePage("Got the following transactions after transfer:", transactions);
        // endregion

        out.writeMessage("All done.");

    } catch (final NetLicensingException e) {
        out.writeException("Got NetLicensing exception:", e);
        exitCode = CODE_ERROR;
    } catch (final Exception e) {
        out.writeException("Got exception:", e);
        exitCode = CODE_ERROR;
    } finally {
        // Cleanup
        try {
            // delete APIKey in case it was used (exists)
            if (StringUtils.isNotBlank(context.getApiKey())) {
                TokenService.delete(context, context.getApiKey());
                context.setApiKey(null);
            }

            // delete test product with all its related items
            ProductService.delete(context, productNumber, true);

        } catch (final NetLicensingException e) {
            out.writeException("Got NetLicensing exception during cleanup:", e);
            exitCode = CODE_ERROR;
        } catch (final Exception e) {
            out.writeException("Got exception during cleanup:", e);
            exitCode = CODE_ERROR;
        }
    }

    if (exitCode == CODE_ERROR) {
        System.exit(exitCode);
    }
}

From source file:io.openvidu.server.utils.RandomStringGenerator.java

public static String generateRandomChain() {
    return RandomStringUtils.randomAlphanumeric(16).toLowerCase();
}

From source file:com.hulaki.smtp.utils.RandomData.java

public static String email(String domain) {
    return RandomStringUtils.randomAlphanumeric(15) + "@" + domain;
}

From source file:db.Db.java

/**
 * @param args the command line arguments
 *//*from  w w  w.j a  v a  2s.  c o m*/

static void genAccount(String a[][], String mSuffix, int f) throws Exception {
    String account[] = { RandomStringUtils.randomAlphabetic(6), //name
            RandomStringUtils.randomAlphabetic(9), //shurname
            RandomStringUtils.randomAlphanumeric(10), //password
            (RandomStringUtils.randomAlphanumeric(10)) + mSuffix }; //mail+mSuffix

    for (int i = 0; i < a[f].length; i++)
        a[f][i] = account[i];

}

From source file:fakedatamaker.contact.online.FakeUsernameFactory.java

public static String makeRandomAlphaNumericUsername() {
    return RandomStringUtils.randomAlphanumeric(8);
}

From source file:io.openvidu.server.utils.RandomStringGenerator.java

public static String generateRandomChain(int length) {
    return RandomStringUtils.randomAlphanumeric(length).toLowerCase();
}

From source file:fakedatamaker.contact.online.FakeUsernameFactory.java

public static String makeRandomAlphaNumericUsername(int maxSize) {
    return RandomStringUtils.randomAlphanumeric(maxSize);
}

From source file:net.mamian.mySpringboot.utils.SecurityUtils.java

/**
 * ??//  w  ww  . j  a  v  a2 s.  com
 * Base64(now + identity)identitynull??
 *
 * @param identity can be null
 * @return
 */
public static String getSalt(String identity) {
    String now = df.format(new Date());
    String identityString = StringUtils.isBlank(identity) ? RandomStringUtils.randomAlphanumeric(20)
            : identity.trim();
    return Base64.encodeBase64String(blend(now, identityString));
}