Example usage for java.util Calendar getInstance

List of usage examples for java.util Calendar getInstance

Introduction

In this page you can find the example usage for java.util Calendar getInstance.

Prototype

public static Calendar getInstance() 

Source Link

Document

Gets a calendar using the default time zone and locale.

Usage

From source file:com.appeligo.epg.EpgIndexer.java

public static void main(String[] args) throws Exception {
    HessianProxyFactory factory = new HessianProxyFactory();
    EPGProvider epg = (EPGProvider) factory.create(EPGProvider.class, "http://localhost/epg/channel.epg");
    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, -5);//from w w w.j  a  v  a 2 s  .  c  om
    cal.set(Calendar.DATE, 1);
    String[] lineups = new String[] { "SDTW-C", "P-C", "P-DC", "P-S", "M-C", "M-DC", "M-S", "E-C", "E-DC",
            "E-S", "H-C", "H-DC", "H-S" };
    List<String> ids = epg.getModifiedProgramIds(cal.getTime());
    int count = 0;
    long average = 0;
    int counter = 0;
    int added = 0;
    while (count < ids.size()) {
        System.err.println("in loop: " + counter + ", " + count + "," + ids.size());
        int subsetSize = (ids.size() < 100 ? ids.size() : 100);
        counter++;
        if (count % 1000 == 0) {
            log.debug("Index programs into the Lucene Index. Current have processed " + count
                    + " programs out of " + ids.size());
        }
        int endIndex = (count + subsetSize > ids.size() ? ids.size() : count + subsetSize);
        List<String> subset = ids.subList(count, endIndex);
        count += subsetSize;

        long time = System.currentTimeMillis();
        HashMap<String, List<ScheduledProgram>> schedules = new HashMap<String, List<ScheduledProgram>>();
        for (String lineup : lineups) {
            ScheduledProgram[] programs = epg.getNextShowingList(lineup, subset);
            for (ScheduledProgram program : programs) {
                if (program != null) {
                    List<ScheduledProgram> schedule = schedules.get(program.getProgramId());
                    if (schedule == null) {
                        schedule = new ArrayList<ScheduledProgram>();
                        schedules.put(program.getProgramId(), schedule);
                    }
                    schedule.add(program);
                    added++;
                }
            }
        }
        long after = System.currentTimeMillis();
        long diff = after - time;
        average += diff;
        System.err.println(diff + " - " + (average / counter) + " added: " + added);
    }
    //      EpgIndexer indexer = new EpgIndexer(programIndex, epg, lineup);
    //      Calendar cal = Calendar.getInstance();
    //      cal.set(Calendar.DAY_OF_MONTH, 24);
    //      cal.set(Calendar.HOUR_OF_DAY, 0);
    //      indexer.updateEpgIndex(cal.getTime());
}

From source file:com.microsoft.windowsazure.services.media.samples.contentprotection.playreadywidevine.Program.java

public static void main(String[] args) {
    try {//from   w w  w  . j a v a 2  s. c  o m
        // Set up the MediaContract object to call into the Media Services account
        Configuration configuration = MediaConfiguration.configureWithOAuthAuthentication(mediaServiceUri,
                oAuthUri, clientId, clientSecret, scope);
        mediaService = MediaService.create(configuration);

        System.out.println("Azure SDK for Java - PlayReady & Widevine Dynamic Encryption Sample");

        // Upload a local file to a media asset.
        AssetInfo uploadAsset = uploadFileAndCreateAsset("Azure-Video.wmv");
        System.out.println("Uploaded Asset Id: " + uploadAsset.getId());

        // Transform the asset.
        AssetInfo encodedAsset = encode(uploadAsset);
        System.out.println("Encoded Asset Id: " + encodedAsset.getId());

        // Create the ContentKey
        ContentKeyInfo contentKeyInfo = createCommonTypeContentKey(encodedAsset);
        System.out.println("Common Encryption Content Key: " + contentKeyInfo.getId());

        // Create the ContentKeyAuthorizationPolicy
        String tokenTemplateString = null;
        if (tokenRestriction) {
            tokenTemplateString = addTokenRestrictedAuthorizationPolicy(contentKeyInfo, tokenType);
        } else {
            addOpenAuthorizationPolicy(contentKeyInfo);
        }

        // Create the AssetDeliveryPolicy
        createAssetDeliveryPolicy(encodedAsset, contentKeyInfo);

        if (tokenTemplateString != null) {
            // Deserializes a string containing the XML representation of the TokenRestrictionTemplate
            TokenRestrictionTemplate tokenTemplate = TokenRestrictionTemplateSerializer
                    .deserialize(tokenTemplateString);

            // Generate a test token based on the the data in the given
            // TokenRestrictionTemplate.
            // Note: You need to pass the key id Guid because we specified
            // TokenClaim.ContentKeyIdentifierClaim in during the creation
            // of TokenRestrictionTemplate.
            UUID rawKey = UUID.fromString(contentKeyInfo.getId().substring("nb:kid:UUID:".length()));

            // Token expiration: 1-year
            Calendar date = Calendar.getInstance();
            date.setTime(new Date());
            date.add(Calendar.YEAR, 1);

            // Generate token
            String testToken = TokenRestrictionTemplateSerializer.generateTestToken(tokenTemplate, null, rawKey,
                    date.getTime(), null);

            System.out.println(tokenTemplate.getTokenType().toString() + " Test Token: Bearer " + testToken);
        }

        // Create the Streaming Origin Locator
        String url = getStreamingOriginLocator(encodedAsset);

        System.out.println("Origin Locator Url: " + url);
        System.out.println("Sample completed!");
    } catch (ServiceException se) {
        System.out.println("ServiceException encountered.");
        System.out.println(se.toString());
    } catch (Exception e) {
        System.out.println("Exception encountered.");
        System.out.println(e.toString());
    }
}

From source file:se.technipelago.weather.chart.Generator.java

public static void main(String[] args) {

    Generator generator = new Generator();

    if (args.length > 0) {
        String outputDir = args[0];
        if (outputDir.endsWith("/")) {
            outputDir = outputDir.substring(0, outputDir.length() - 1);
        }/* www.jav a 2s .co m*/
        generator.setOutputDirectory(outputDir);
    }

    // Generate charts.
    generator.init();
    Map<String, Object> data = generator.getWeatherData();
    generator.generateCurrentCharts(data);
    generator.generateHistoryCharts(-30, 31);
    int year = Calendar.getInstance().get(Calendar.YEAR);
    generator.generateMonthlyCharts(year);
    generator.generateYearlyCharts(year);
}

From source file:com.acceleratedio.pac_n_zoom.UploadVideo.java

/**
 * Upload the user-selected video to the user's YouTube channel. The code
 * looks for the video in the application's project folder and uses OAuth
 * 2.0 to authorize the API request.//from   w  w w  .j  a v a 2 s.  c om
 *
 * @param args command line args (not used).
 */
public static void main(String[] args) {

    MakePostRequest get_video = new MakePostRequest();
    get_video.execute();

    // This OAuth 2.0 access scope allows an application to upload files
    // to the authenticated user's YouTube channel, but doesn't allow
    // other types of access.
    List<String> scopes = Lists.newArrayList("https://www.googleapis.com/auth/youtube.upload");

    String vidFileName = PickAnmActivity.fil_nams[position].replace('/', '?') + ".mp4";
    String httpAddrs = "http://www.pnzanimate.me/Droid/db_rd.php?";
    httpAddrs += vidFileName;

    try {
        // Authorize the request.
        Credential credential = Auth.authorize(scopes, "uploadvideo");

        // This object is used to make YouTube Data API requests.
        youtube = new YouTube.Builder(Auth.HTTP_TRANSPORT, Auth.JSON_FACTORY, credential)
                .setApplicationName("youtube-cmdline-uploadvideo-sample").build();

        System.out.println("Uploading: " + SAMPLE_VIDEO_FILENAME);

        // Add extra information to the video before uploading.
        Video videoObjectDefiningMetadata = new Video();

        // Set the video to be publicly visible. This is the default
        // setting. Other supporting settings are "unlisted" and "private."
        VideoStatus status = new VideoStatus();
        status.setPrivacyStatus("public");
        videoObjectDefiningMetadata.setStatus(status);

        // Most of the video's metadata is set on the VideoSnippet object.
        VideoSnippet snippet = new VideoSnippet();

        // This code uses a Calendar instance to create a unique name and
        // description for test purposes so that you can easily upload
        // multiple files. You should remove this code from your project
        // and use your own standard names instead.
        Calendar cal = Calendar.getInstance();
        snippet.setTitle("Test Upload via Java on " + cal.getTime());
        snippet.setDescription(
                "Video uploaded via YouTube Data API V3 using the Java library " + "on " + cal.getTime());

        // Set the keyword tags that you want to associate with the video.
        List<String> tags = new ArrayList<String>();
        tags.add("test");
        tags.add("example");
        tags.add("java");
        tags.add("YouTube Data API V3");
        tags.add("erase me");
        snippet.setTags(tags);

        // Add the completed snippet object to the video resource.
        videoObjectDefiningMetadata.setSnippet(snippet);

        InputStreamContent mediaContent = new InputStreamContent("mp4",
                UploadVideo.class.getResourceAsStream("/sample-video.mp4"));

        // Insert the video. The command sends three arguments. The first
        // specifies which information the API request is setting and which
        // information the API response should return. The second argument
        // is the video resource that contains metadata about the new video.
        // The third argument is the actual video content.
        YouTube.Videos.Insert videoInsert = youtube.videos().insert("snippet,statistics,status",
                videoObjectDefiningMetadata, mediaContent);

        // Set the upload type and add an event listener.
        MediaHttpUploader uploader = videoInsert.getMediaHttpUploader();

        // Indicate whether direct media upload is enabled. A value of
        // "True" indicates that direct media upload is enabled and that
        // the entire media content will be uploaded in a single request.
        // A value of "False," which is the default, indicates that the
        // request will use the resumable media upload protocol, which
        // supports the ability to resume an upload operation after a
        // network interruption or other transmission failure, saving
        // time and bandwidth in the event of network failures.
        uploader.setDirectUploadEnabled(false);

        MediaHttpUploaderProgressListener progressListener = new MediaHttpUploaderProgressListener() {
            public void progressChanged(MediaHttpUploader uploader) throws IOException {
                switch (uploader.getUploadState()) {
                case INITIATION_STARTED:
                    System.out.println("Initiation Started");
                    break;
                case INITIATION_COMPLETE:
                    System.out.println("Initiation Completed");
                    break;
                case MEDIA_IN_PROGRESS:
                    System.out.println("Upload in progress");
                    System.out.println("Upload percentage: " + uploader.getProgress());
                    break;
                case MEDIA_COMPLETE:
                    System.out.println("Upload Completed!");
                    break;
                case NOT_STARTED:
                    System.out.println("Upload Not Started!");
                    break;
                }
            }
        };
        uploader.setProgressListener(progressListener);

        // Call the API and upload the video.
        Video returnedVideo = videoInsert.execute();

        // Print data about the newly inserted video from the API response.
        System.out.println("\n================== Returned Video ==================\n");
        System.out.println("  - Id: " + returnedVideo.getId());
        System.out.println("  - Title: " + returnedVideo.getSnippet().getTitle());
        System.out.println("  - Tags: " + returnedVideo.getSnippet().getTags());
        System.out.println("  - Privacy Status: " + returnedVideo.getStatus().getPrivacyStatus());
        System.out.println("  - Video Count: " + returnedVideo.getStatistics().getViewCount());

    } catch (GoogleJsonResponseException e) {
        System.err.println("GoogleJsonResponseException code: " + e.getDetails().getCode() + " : "
                + e.getDetails().getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        System.err.println("IOException: " + e.getMessage());
        e.printStackTrace();
    } catch (Throwable t) {
        System.err.println("Throwable: " + t.getMessage());
        t.printStackTrace();
    }
}

From source file:Pathway2RDFv2.java

public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException,
        ServiceException, ClassNotFoundException, IDMapperException, ParseException {

    int softwareVersion = 0;
    int schemaVersion = 0;
    int latestRevision = 0;

    BioDataSource.init();//www . j ava 2s. c om
    Class.forName("org.bridgedb.rdb.IDMapperRdb");
    File dir = new File("/Users/andra/Downloads/bridge");
    File[] bridgeDbFiles = dir.listFiles();
    IDMapperStack mapper = new IDMapperStack();
    for (File bridgeDbFile : bridgeDbFiles) {
        System.out.println(bridgeDbFile.getAbsolutePath());
        mapper.addIDMapper("idmapper-pgdb:" + bridgeDbFile.getAbsolutePath());
    }

    Model bridgeDbmodel = ModelFactory.createDefaultModel();
    InputStream in = new FileInputStream("/tmp/BioDataSource.ttl");
    bridgeDbmodel.read(in, "", "TURTLE");

    WikiPathwaysClient client = new WikiPathwaysClient(
            new URL("http://www.wikipathways.org/wpi/webservice/webservice.php"));

    basicCalls.printMemoryStatus();

    //Map wikipathway organisms to NCBI organisms
    HashMap<String, String> organismTaxonomy = wpRelatedCalls.getOrganismsTaxonomyMapping();
    //HashMap<String, String> miriamSources = new HashMap<String, String>();
    //      HashMap<String, Str ing> miriamLinks = basicCalls.getMiriamUriBridgeDb();

    //Document wikiPathwaysDom = basicCalls.openXmlFile(args[0]);
    Document wikiPathwaysDom = basicCalls.openXmlFile("/tmp/WpGPML.xml");

    //initiate the Jena model to be populated
    Model model = ModelFactory.createDefaultModel();
    Model voidModel = ModelFactory.createDefaultModel();

    voidModel.setNsPrefix("xsd", XSD.getURI());
    voidModel.setNsPrefix("void", Void.getURI());
    voidModel.setNsPrefix("wprdf", "http://rdf.wikipathways.org/");
    voidModel.setNsPrefix("pav", Pav.getURI());
    voidModel.setNsPrefix("prov", Prov.getURI());
    voidModel.setNsPrefix("dcterms", DCTerms.getURI());
    voidModel.setNsPrefix("biopax", Biopax_level3.getURI());
    voidModel.setNsPrefix("gpml", Gpml.getURI());
    voidModel.setNsPrefix("wp", Wp.getURI());
    voidModel.setNsPrefix("foaf", FOAF.getURI());
    voidModel.setNsPrefix("hmdb", "http://identifiers.org/hmdb/");
    voidModel.setNsPrefix("freq", Freq.getURI());
    voidModel.setNsPrefix("dc", DC.getURI());
    setModelPrefix(model);

    //Populate void.ttl
    Calendar now = Calendar.getInstance();
    Literal nowLiteral = voidModel.createTypedLiteral(now);
    Literal titleLiteral = voidModel.createLiteral("WikiPathways-RDF VoID Description", "en");
    Literal descriptionLiteral = voidModel
            .createLiteral("This is the VoID description for a WikiPathwyas-RDF dataset.", "en");
    Resource voidBase = voidModel.createResource("http://rdf.wikipathways.org/");
    Resource identifiersOrg = voidModel.createResource("http://identifiers.org");
    Resource wpHomeBase = voidModel.createResource("http://www.wikipathways.org/");
    Resource authorResource = voidModel
            .createResource("http://semantics.bigcat.unimaas.nl/figshare/search_author.php?author=waagmeester");
    Resource apiResource = voidModel
            .createResource("http://www.wikipathways.org/wpi/webservice/webservice.php");
    Resource mainDatadump = voidModel.createResource("http://rdf.wikipathways.org/wpContent.ttl.gz");
    Resource license = voidModel.createResource("http://creativecommons.org/licenses/by/3.0/");
    Resource instituteResource = voidModel.createResource("http://dbpedia.org/page/Maastricht_University");
    voidBase.addProperty(RDF.type, Void.Dataset);
    voidBase.addProperty(DCTerms.title, titleLiteral);
    voidBase.addProperty(DCTerms.description, descriptionLiteral);
    voidBase.addProperty(FOAF.homepage, wpHomeBase);
    voidBase.addProperty(DCTerms.license, license);
    voidBase.addProperty(Void.uriSpace, voidBase);
    voidBase.addProperty(Void.uriSpace, identifiersOrg);
    voidBase.addProperty(Pav.importedBy, authorResource);
    voidBase.addProperty(Pav.importedFrom, apiResource);
    voidBase.addProperty(Pav.importedOn, nowLiteral);
    voidBase.addProperty(Void.dataDump, mainDatadump);
    voidBase.addProperty(Voag.frequencyOfChange, Freq.Irregular);
    voidBase.addProperty(Pav.createdBy, authorResource);
    voidBase.addProperty(Pav.createdAt, instituteResource);
    voidBase.addLiteral(Pav.createdOn, nowLiteral);
    voidBase.addProperty(DCTerms.subject, Biopax_level3.Pathway);
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/ncbigene/2678"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/pubmed/15215856"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/hmdb/HMDB02005"));
    voidBase.addProperty(Void.exampleResource, voidModel.createResource("http://rdf.wikipathways.org/WP15"));
    voidBase.addProperty(Void.exampleResource,
            voidModel.createResource("http://identifiers.org/obo.chebi/17242"));

    for (String organism : organismTaxonomy.values()) {
        voidBase.addProperty(DCTerms.subject,
                voidModel.createResource("http://dbpedia.org/page/" + organism.replace(" ", "_")));
    }
    voidBase.addProperty(Void.vocabulary, Biopax_level3.NAMESPACE);
    voidBase.addProperty(Void.vocabulary, voidModel.createResource(Wp.getURI()));
    voidBase.addProperty(Void.vocabulary, voidModel.createResource(Gpml.getURI()));
    voidBase.addProperty(Void.vocabulary, FOAF.NAMESPACE);
    voidBase.addProperty(Void.vocabulary, Pav.NAMESPACE);
    //Custom Properties
    String baseUri = "http://rdf.wikipathways.org/";
    NodeList pathwayElements = wikiPathwaysDom.getElementsByTagName("Pathway");

    //BioDataSource.init();
    for (int i = 0; i < pathwayElements.getLength(); i++) {
        Model pathwayModel = createPathwayModel();
        String wpId = pathwayElements.item(i).getAttributes().getNamedItem("identifier").getTextContent();
        String revision = pathwayElements.item(i).getAttributes().getNamedItem("revision").getTextContent();
        String pathwayOrganism = "";
        if (pathwayElements.item(i).getAttributes().getNamedItem("Organism") != null)
            pathwayOrganism = pathwayElements.item(i).getAttributes().getNamedItem("Organism").getTextContent()
                    .trim();
        if (Integer.valueOf(revision) > latestRevision) {
            latestRevision = Integer.valueOf(revision);
        }
        File f = new File("/tmp/" + args[0] + "/" + wpId + "_r" + revision + ".ttl");
        System.out.println(f.getName());
        if (!f.exists()) {

            Resource voidPwResource = wpRelatedCalls.addVoidTriples(voidModel, voidBase,
                    pathwayElements.item(i), client);
            Resource pwResource = wpRelatedCalls.addPathwayLevelTriple(pathwayModel, pathwayElements.item(i),
                    organismTaxonomy);

            // Get the comments
            NodeList commentElements = ((Element) pathwayElements.item(i)).getElementsByTagName("Comment");
            wpRelatedCalls.addCommentTriples(pathwayModel, pwResource, commentElements, wpId, revision);
            // Get the Groups
            NodeList groupElements = ((Element) pathwayElements.item(i)).getElementsByTagName("Group");
            for (int n = 0; n < groupElements.getLength(); n++) {
                wpRelatedCalls.addGroupTriples(pathwayModel, pwResource, groupElements.item(n), wpId, revision);
            }
            // Get all the Datanodes
            NodeList dataNodesElement = ((Element) pathwayElements.item(i)).getElementsByTagName("DataNode");
            for (int j = 0; j < dataNodesElement.getLength(); j++) {
                wpRelatedCalls.addDataNodeTriples(pathwayModel, pwResource, dataNodesElement.item(j), wpId,
                        revision, bridgeDbmodel, mapper);
            }
            // Get all the lines
            NodeList linesElement = ((Element) pathwayElements.item(i)).getElementsByTagName("Line");
            for (int k = 0; k < linesElement.getLength(); k++) {
                wpRelatedCalls.addLineTriples(pathwayModel, pwResource, linesElement.item(k), wpId, revision);
            }
            //Get all the labels
            NodeList labelsElement = ((Element) pathwayElements.item(i)).getElementsByTagName("Label");
            for (int l = 0; l < labelsElement.getLength(); l++) {
                wpRelatedCalls.addLabelTriples(pathwayModel, pwResource, labelsElement.item(l), wpId, revision);
            }
            NodeList referenceElements = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:PublicationXref");
            for (int m = 0; m < referenceElements.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements.item(m), wpId,
                        revision);
            }
            NodeList referenceElements2 = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:publicationXref");
            for (int m = 0; m < referenceElements2.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements2.item(m), wpId,
                        revision);
            }
            NodeList referenceElements3 = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:PublicationXRef");
            for (int m = 0; m < referenceElements3.getLength(); m++) {
                wpRelatedCalls.addReferenceTriples(pathwayModel, pwResource, referenceElements3.item(m), wpId,
                        revision);
            }

            NodeList ontologyElements = ((Element) pathwayElements.item(i))
                    .getElementsByTagName("bp:openControlledVocabulary");
            for (int n = 0; n < ontologyElements.getLength(); n++) {
                wpRelatedCalls.addPathwayOntologyTriples(pathwayModel, pwResource, ontologyElements.item(n));
            }
            System.out.println(wpId);
            basicCalls.saveRDF2File(pathwayModel, "/tmp/" + args[0] + "/" + wpId + "_r" + revision + ".ttl",
                    "TURTLE");

            model.add(pathwayModel);
            pathwayModel.removeAll();
        }
    }
    Date myDate = new Date();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
    String myDateString = sdf.format(myDate);
    FileUtils.writeStringToFile(new File("latestVersion.txt"),
            "v" + schemaVersion + "." + softwareVersion + "." + latestRevision + "_" + myDateString);
    basicCalls.saveRDF2File(model, "/tmp/wpContent_v" + schemaVersion + "." + softwareVersion + "."
            + latestRevision + "_" + myDateString + ".ttl", "TURTLE");
    basicCalls.saveRDF2File(voidModel, "/tmp/void.ttl", "TURTLE");
}

From source file:UploadUrlGenerator.java

public static void main(String[] args) throws Exception {
    Options opts = new Options();

    opts.addOption(Option.builder().longOpt(ENDPOINT_OPTION).required().hasArg().argName("url")
            .desc("Sets the ECS S3 endpoint to use, e.g. https://ecs.company.com:9021").build());
    opts.addOption(Option.builder().longOpt(ACCESS_KEY_OPTION).required().hasArg().argName("access-key")
            .desc("Sets the Access Key (user) to sign the request").build());
    opts.addOption(Option.builder().longOpt(SECRET_KEY_OPTION).required().hasArg().argName("secret")
            .desc("Sets the secret key to sign the request").build());
    opts.addOption(Option.builder().longOpt(BUCKET_OPTION).required().hasArg().argName("bucket-name")
            .desc("The bucket containing the object").build());
    opts.addOption(Option.builder().longOpt(KEY_OPTION).required().hasArg().argName("object-key")
            .desc("The object name (key) to access with the URL").build());
    opts.addOption(Option.builder().longOpt(EXPIRES_OPTION).hasArg().argName("minutes")
            .desc("Minutes from local time to expire the request.  1 day = 1440, 1 week=10080, "
                    + "1 month (30 days)=43200, 1 year=525600.  Defaults to 1 hour (60).")
            .build());/*www  .  j a  va 2 s.co  m*/
    opts.addOption(Option.builder().longOpt(VERB_OPTION).hasArg().argName("http-verb").type(HttpMethod.class)
            .desc("The HTTP verb that will be used with the URL (PUT, GET, etc).  Defaults to GET.").build());
    opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPTION).hasArg().argName("mimetype")
            .desc("Sets the Content-Type header (e.g. image/jpeg) that will be used with the request.  "
                    + "Must match exactly.  Defaults to application/octet-stream for PUT/POST and "
                    + "null for all others")
            .build());

    DefaultParser dp = new DefaultParser();

    CommandLine cmd = null;
    try {
        cmd = dp.parse(opts, args);
    } catch (ParseException e) {
        System.err.println("Error: " + e.getMessage());
        HelpFormatter hf = new HelpFormatter();
        hf.printHelp("java -jar UploadUrlGenerator-xxx.jar", opts, true);
        System.exit(255);
    }

    URI endpoint = URI.create(cmd.getOptionValue(ENDPOINT_OPTION));
    String accessKey = cmd.getOptionValue(ACCESS_KEY_OPTION);
    String secretKey = cmd.getOptionValue(SECRET_KEY_OPTION);
    String bucket = cmd.getOptionValue(BUCKET_OPTION);
    String key = cmd.getOptionValue(KEY_OPTION);
    HttpMethod method = HttpMethod.GET;
    if (cmd.hasOption(VERB_OPTION)) {
        method = HttpMethod.valueOf(cmd.getOptionValue(VERB_OPTION).toUpperCase());
    }
    int expiresMinutes = 60;
    if (cmd.hasOption(EXPIRES_OPTION)) {
        expiresMinutes = Integer.parseInt(cmd.getOptionValue(EXPIRES_OPTION));
    }
    String contentType = null;
    if (method == HttpMethod.PUT || method == HttpMethod.POST) {
        contentType = "application/octet-stream";
    }

    if (cmd.hasOption(CONTENT_TYPE_OPTION)) {
        contentType = cmd.getOptionValue(CONTENT_TYPE_OPTION);
    }

    BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey);
    ClientConfiguration cc = new ClientConfiguration();
    // Force use of v2 Signer.  ECS does not support v4 signatures yet.
    cc.setSignerOverride("S3SignerType");
    AmazonS3Client s3 = new AmazonS3Client(credentials, cc);
    s3.setEndpoint(endpoint.toString());
    S3ClientOptions s3c = new S3ClientOptions();
    s3c.setPathStyleAccess(true);
    s3.setS3ClientOptions(s3c);

    // Sign the URL
    Calendar c = Calendar.getInstance();
    c.add(Calendar.MINUTE, expiresMinutes);
    GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key).withExpiration(c.getTime())
            .withMethod(method);
    if (contentType != null) {
        req = req.withContentType(contentType);
    }
    URL u = s3.generatePresignedUrl(req);
    System.out.printf("URL: %s\n", u.toURI().toASCIIString());
    System.out.printf("HTTP Verb: %s\n", method);
    System.out.printf("Expires: %s\n", c.getTime());
    System.out.println("To Upload with curl:");

    StringBuilder sb = new StringBuilder();
    sb.append("curl ");

    if (method != HttpMethod.GET) {
        sb.append("-X ");
        sb.append(method.toString());
        sb.append(" ");
    }

    if (contentType != null) {
        sb.append("-H \"Content-Type: ");
        sb.append(contentType);
        sb.append("\" ");
    }

    if (method == HttpMethod.POST || method == HttpMethod.PUT) {
        sb.append("-T <filename> ");
    }

    sb.append("\"");
    sb.append(u.toURI().toASCIIString());
    sb.append("\"");

    System.out.println(sb.toString());

    System.exit(0);
}

From source file:FormatStorage2ColumnStorageMR.java

@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {

    if (args.length != 2) {
        System.out.println("FormatStorage2ColumnStorageMR <input> <output>");
        System.exit(-1);//from w w  w.  ja  va2  s. c o m
    }

    JobConf conf = new JobConf(FormatStorageMR.class);

    conf.setJobName("FormatStorage2ColumnStorageMR");

    conf.setNumMapTasks(1);
    conf.setNumReduceTasks(4);

    conf.setOutputKeyClass(LongWritable.class);
    conf.setOutputValueClass(Unit.Record.class);

    conf.setMapperClass(FormatStorageMapper.class);
    conf.setReducerClass(ColumnStorageReducer.class);

    conf.setInputFormat(FormatStorageInputFormat.class);
    conf.set("mapred.output.compress", "flase");

    Head head = new Head();
    initHead(head);

    head.toJobConf(conf);

    FileInputFormat.setInputPaths(conf, args[0]);
    Path outputPath = new Path(args[1]);
    FileOutputFormat.setOutputPath(conf, outputPath);

    FileSystem fs = outputPath.getFileSystem(conf);
    fs.delete(outputPath, true);

    JobClient jc = new JobClient(conf);
    RunningJob rj = null;
    rj = jc.submitJob(conf);

    String lastReport = "";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
    long reportTime = System.currentTimeMillis();
    long maxReportInterval = 3 * 1000;
    while (!rj.isComplete()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }

        int mapProgress = Math.round(rj.mapProgress() * 100);
        int reduceProgress = Math.round(rj.reduceProgress() * 100);

        String report = " map = " + mapProgress + "%,  reduce = " + reduceProgress + "%";

        if (!report.equals(lastReport) || System.currentTimeMillis() >= reportTime + maxReportInterval) {

            String output = dateFormat.format(Calendar.getInstance().getTime()) + report;
            System.out.println(output);
            lastReport = report;
            reportTime = System.currentTimeMillis();
        }
    }

    System.exit(0);

}

From source file:search.java

public static void main(String argv[]) {
    int optind;/*from w  w w.j  a va 2  s. c  o  m*/

    String subject = null;
    String from = null;
    boolean or = false;
    boolean today = false;
    int size = -1;

    for (optind = 0; optind < argv.length; optind++) {
        if (argv[optind].equals("-T")) {
            protocol = argv[++optind];
        } else if (argv[optind].equals("-H")) {
            host = argv[++optind];
        } else if (argv[optind].equals("-U")) {
            user = argv[++optind];
        } else if (argv[optind].equals("-P")) {
            password = argv[++optind];
        } else if (argv[optind].equals("-or")) {
            or = true;
        } else if (argv[optind].equals("-D")) {
            debug = true;
        } else if (argv[optind].equals("-f")) {
            mbox = argv[++optind];
        } else if (argv[optind].equals("-L")) {
            url = argv[++optind];
        } else if (argv[optind].equals("-subject")) {
            subject = argv[++optind];
        } else if (argv[optind].equals("-from")) {
            from = argv[++optind];
        } else if (argv[optind].equals("-today")) {
            today = true;
        } else if (argv[optind].equals("-size")) {
            size = Integer.parseInt(argv[++optind]);
        } else if (argv[optind].equals("--")) {
            optind++;
            break;
        } else if (argv[optind].startsWith("-")) {
            System.out.println("Usage: search [-D] [-L url] [-T protocol] [-H host] "
                    + "[-U user] [-P password] [-f mailbox] "
                    + "[-subject subject] [-from from] [-or] [-today]");
            System.exit(1);
        } else {
            break;
        }
    }

    try {

        if ((subject == null) && (from == null) && !today && size < 0) {
            System.out.println("Specify either -subject, -from, -today, or -size");
            System.exit(1);
        }

        // Get a Properties object
        Properties props = System.getProperties();

        // Get a Session object
        Session session = Session.getInstance(props, null);
        session.setDebug(debug);

        // Get a Store object
        Store store = null;
        if (url != null) {
            URLName urln = new URLName(url);
            store = session.getStore(urln);
            store.connect();
        } else {
            if (protocol != null)
                store = session.getStore(protocol);
            else
                store = session.getStore();

            // Connect
            if (host != null || user != null || password != null)
                store.connect(host, user, password);
            else
                store.connect();
        }

        // Open the Folder

        Folder folder = store.getDefaultFolder();
        if (folder == null) {
            System.out.println("Cant find default namespace");
            System.exit(1);
        }

        folder = folder.getFolder(mbox);
        if (folder == null) {
            System.out.println("Invalid folder");
            System.exit(1);
        }

        folder.open(Folder.READ_ONLY);
        SearchTerm term = null;

        if (subject != null)
            term = new SubjectTerm(subject);
        if (from != null) {
            FromStringTerm fromTerm = new FromStringTerm(from);
            if (term != null) {
                if (or)
                    term = new OrTerm(term, fromTerm);
                else
                    term = new AndTerm(term, fromTerm);
            } else
                term = fromTerm;
        }
        if (today) {
            Calendar c = Calendar.getInstance();
            c.set(Calendar.HOUR, 0);
            c.set(Calendar.MINUTE, 0);
            c.set(Calendar.SECOND, 0);
            c.set(Calendar.MILLISECOND, 0);
            c.set(Calendar.AM_PM, Calendar.AM);
            ReceivedDateTerm startDateTerm = new ReceivedDateTerm(ComparisonTerm.GE, c.getTime());
            c.add(Calendar.DATE, 1); // next day
            ReceivedDateTerm endDateTerm = new ReceivedDateTerm(ComparisonTerm.LT, c.getTime());
            SearchTerm dateTerm = new AndTerm(startDateTerm, endDateTerm);
            if (term != null) {
                if (or)
                    term = new OrTerm(term, dateTerm);
                else
                    term = new AndTerm(term, dateTerm);
            } else
                term = dateTerm;
        }

        if (size >= 0) {
            SizeTerm sizeTerm = new SizeTerm(ComparisonTerm.GT, size);
            if (term != null) {
                if (or)
                    term = new OrTerm(term, sizeTerm);
                else
                    term = new AndTerm(term, sizeTerm);
            } else
                term = sizeTerm;
        }

        Message[] msgs = folder.search(term);
        System.out.println("FOUND " + msgs.length + " MESSAGES");
        if (msgs.length == 0) // no match
            System.exit(1);

        // Use a suitable FetchProfile
        FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.ENVELOPE);
        folder.fetch(msgs, fp);

        for (int i = 0; i < msgs.length; i++) {
            System.out.println("--------------------------");
            System.out.println("MESSAGE #" + (i + 1) + ":");
            dumpPart(msgs[i]);
        }

        folder.close(false);
        store.close();
    } catch (Exception ex) {
        System.out.println("Oops, got exception! " + ex.getMessage());
        ex.printStackTrace();
    }

    System.exit(1);
}

From source file:Text2ColumntStorageMR.java

@SuppressWarnings("deprecation")
public static void main(String[] args) throws Exception {

    if (args.length != 3) {
        System.out.println("Text2ColumnStorageMR <input> <output> <columnStorageMode>");
        System.exit(-1);//  w  w  w .  j  av a 2s .  c  om
    }

    JobConf conf = new JobConf(Text2ColumntStorageMR.class);

    conf.setJobName("Text2ColumnStorageMR");

    conf.setNumMapTasks(1);
    conf.setNumReduceTasks(4);

    conf.setOutputKeyClass(LongWritable.class);
    conf.setOutputValueClass(Unit.Record.class);

    conf.setMapperClass(TextFileMapper.class);
    conf.setReducerClass(ColumnStorageReducer.class);

    conf.setInputFormat(TextInputFormat.class);
    conf.setOutputFormat((Class<? extends OutputFormat>) ColumnStorageHiveOutputFormat.class);
    conf.set("mapred.output.compress", "flase");

    Head head = new Head();
    initHead(head);

    head.toJobConf(conf);

    int bt = Integer.valueOf(args[2]);

    FileInputFormat.setInputPaths(conf, args[0]);
    Path outputPath = new Path(args[1]);
    FileOutputFormat.setOutputPath(conf, outputPath);

    FileSystem fs = outputPath.getFileSystem(conf);
    fs.delete(outputPath, true);

    JobClient jc = new JobClient(conf);
    RunningJob rj = null;
    rj = jc.submitJob(conf);

    String lastReport = "";
    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss,SSS");
    long reportTime = System.currentTimeMillis();
    long maxReportInterval = 3 * 1000;
    while (!rj.isComplete()) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }

        int mapProgress = Math.round(rj.mapProgress() * 100);
        int reduceProgress = Math.round(rj.reduceProgress() * 100);

        String report = " map = " + mapProgress + "%,  reduce = " + reduceProgress + "%";

        if (!report.equals(lastReport) || System.currentTimeMillis() >= reportTime + maxReportInterval) {

            String output = dateFormat.format(Calendar.getInstance().getTime()) + report;
            System.out.println(output);
            lastReport = report;
            reportTime = System.currentTimeMillis();
        }
    }

    System.exit(0);

}

From source file:io.druid.examples.rabbitmq.RabbitMQProducerMain.java

public static void main(String[] args) throws Exception {
    // We use a List to keep track of option insertion order. See below.
    final List<Option> optionList = new ArrayList<Option>();

    optionList.add(OptionBuilder.withLongOpt("help").withDescription("display this help message").create("h"));
    optionList.add(OptionBuilder.withLongOpt("hostname").hasArg()
            .withDescription("the hostname of the AMQP broker [defaults to AMQP library default]").create("b"));
    optionList.add(OptionBuilder.withLongOpt("port").hasArg()
            .withDescription("the port of the AMQP broker [defaults to AMQP library default]").create("n"));
    optionList.add(OptionBuilder.withLongOpt("username").hasArg()
            .withDescription("username to connect to the AMQP broker [defaults to AMQP library default]")
            .create("u"));
    optionList.add(OptionBuilder.withLongOpt("password").hasArg()
            .withDescription("password to connect to the AMQP broker [defaults to AMQP library default]")
            .create("p"));
    optionList.add(OptionBuilder.withLongOpt("vhost").hasArg()
            .withDescription("name of virtual host on the AMQP broker [defaults to AMQP library default]")
            .create("v"));
    optionList.add(OptionBuilder.withLongOpt("exchange").isRequired().hasArg()
            .withDescription("name of the AMQP exchange [required - no default]").create("e"));
    optionList.add(OptionBuilder.withLongOpt("key").hasArg()
            .withDescription("the routing key to use when sending messages [default: 'default.routing.key']")
            .create("k"));
    optionList.add(OptionBuilder.withLongOpt("type").hasArg()
            .withDescription("the type of exchange to create [default: 'topic']").create("t"));
    optionList.add(OptionBuilder.withLongOpt("durable")
            .withDescription("if set, a durable exchange will be declared [default: not set]").create("d"));
    optionList.add(OptionBuilder.withLongOpt("autodelete")
            .withDescription("if set, an auto-delete exchange will be declared [default: not set]")
            .create("a"));
    optionList.add(OptionBuilder.withLongOpt("single")
            .withDescription("if set, only a single message will be sent [default: not set]").create("s"));
    optionList.add(OptionBuilder.withLongOpt("start").hasArg()
            .withDescription("time to use to start sending messages from [default: 2010-01-01T00:00:00]")
            .create());// w  ww. ja  v a  2s.co  m
    optionList.add(OptionBuilder.withLongOpt("stop").hasArg().withDescription(
            "time to use to send messages until (format: '2013-07-18T23:45:59') [default: current time]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("interval").hasArg()
            .withDescription("the interval to add to the timestamp between messages in seconds [default: 10]")
            .create());
    optionList.add(OptionBuilder.withLongOpt("delay").hasArg()
            .withDescription("the delay between sending messages in milliseconds [default: 100]").create());

    // An extremely silly hack to maintain the above order in the help formatting.
    HelpFormatter formatter = new HelpFormatter();
    // Add a comparator to the HelpFormatter using the ArrayList above to sort by insertion order.
    formatter.setOptionComparator(new Comparator() {
        @Override
        public int compare(Object o1, Object o2) {
            // I know this isn't fast, but who cares! The list is short.
            return optionList.indexOf(o1) - optionList.indexOf(o2);
        }
    });

    // Now we can add all the options to an Options instance. This is dumb!
    Options options = new Options();
    for (Option option : optionList) {
        options.addOption(option);
    }

    CommandLine cmd = null;

    try {
        cmd = new BasicParser().parse(options, args);

    } catch (ParseException e) {
        formatter.printHelp("RabbitMQProducerMain", e.getMessage(), options, null);
        System.exit(1);
    }

    if (cmd.hasOption("h")) {
        formatter.printHelp("RabbitMQProducerMain", options);
        System.exit(2);
    }

    ConnectionFactory factory = new ConnectionFactory();

    if (cmd.hasOption("b")) {
        factory.setHost(cmd.getOptionValue("b"));
    }
    if (cmd.hasOption("u")) {
        factory.setUsername(cmd.getOptionValue("u"));
    }
    if (cmd.hasOption("p")) {
        factory.setPassword(cmd.getOptionValue("p"));
    }
    if (cmd.hasOption("v")) {
        factory.setVirtualHost(cmd.getOptionValue("v"));
    }
    if (cmd.hasOption("n")) {
        factory.setPort(Integer.parseInt(cmd.getOptionValue("n")));
    }

    String exchange = cmd.getOptionValue("e");
    String routingKey = "default.routing.key";
    if (cmd.hasOption("k")) {
        routingKey = cmd.getOptionValue("k");
    }

    boolean durable = cmd.hasOption("d");
    boolean autoDelete = cmd.hasOption("a");
    String type = cmd.getOptionValue("t", "topic");
    boolean single = cmd.hasOption("single");
    int interval = Integer.parseInt(cmd.getOptionValue("interval", "10"));
    int delay = Integer.parseInt(cmd.getOptionValue("delay", "100"));

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
    Date stop = sdf.parse(cmd.getOptionValue("stop", sdf.format(new Date())));

    Random r = new Random();
    Calendar timer = Calendar.getInstance();
    timer.setTime(sdf.parse(cmd.getOptionValue("start", "2010-01-01T00:00:00")));

    String msg_template = "{\"utcdt\": \"%s\", \"wp\": %d, \"gender\": \"%s\", \"age\": %d}";

    Connection connection = factory.newConnection();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(exchange, type, durable, autoDelete, null);

    do {
        int wp = (10 + r.nextInt(90)) * 100;
        String gender = r.nextBoolean() ? "male" : "female";
        int age = 20 + r.nextInt(70);

        String line = String.format(msg_template, sdf.format(timer.getTime()), wp, gender, age);

        channel.basicPublish(exchange, routingKey, null, line.getBytes());

        System.out.println("Sent message: " + line);

        timer.add(Calendar.SECOND, interval);

        Thread.sleep(delay);
    } while ((!single && stop.after(timer.getTime())));

    connection.close();
}