Example usage for java.io InputStreamReader InputStreamReader

List of usage examples for java.io InputStreamReader InputStreamReader

Introduction

In this page you can find the example usage for java.io InputStreamReader InputStreamReader.

Prototype

public InputStreamReader(InputStream in, CharsetDecoder dec) 

Source Link

Document

Creates an InputStreamReader that uses the given charset decoder.

Usage

From source file:com.estafeta.flujos.DemoMain.java

/**
 * Clase principal del proyecto/*  w  w w. j  a  va  2 s. c  o  m*/
 * @param args argumentos de linea de comandos
 */
public static void main(String[] args) {
    // init spring context
    ApplicationContext ctx = new ClassPathXmlApplicationContext(APPLOCATION_CONTEXT_FILE);
    // get bean from context
    JmsMessageSender jmsMessageSender = (JmsMessageSender) ctx.getBean(JMS_MESSAGE_SENDER_BEAN_NAME);
    // send to a code specified destination
    Queue queue = new ActiveMQQueue(JMS_DESTINATION_NAME);
    try {
        ClassLoader classLoader = DemoMain.class.getClassLoader();
        FileInputStream fileInputStream = new FileInputStream(
                classLoader.getResource(MOCK_INPUT_FILE).getFile());
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(fileInputStream, Charset.forName(UTF_8_CHARSET)));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            jmsMessageSender.send(queue, line);
        }
        fileInputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // close spring application context
    ((ClassPathXmlApplicationContext) ctx).close();
}

From source file:ar.com.zauber.labs.kraken.providers.wikipedia.apps.administrative.MainAdministrative.java

/**
 * Lee la pagina /*from  w  w  w  . j  av a2  s. c o  m*/
 * http://es.wikipedia.org/wiki/Departamentos_y_partidos_de_la_Argentina
 * la tabla de localidades
 */
public static void main(final String[] args)
        throws IOException, JAXBException, SAXException, URISyntaxException {
    final ConfigurableApplicationContext ctx = new ClassPathXmlApplicationContext(
            "ar/com/zauber/labs/kraken/providers/wikipedia/apps/administrative/"
                    + "config/context-administrative-kraken-spring.xml");
    ctx.registerShutdownHook();

    new ArgentinaDepartmentsSync(
            new BufferedReader(new InputStreamReader(
                    ArgentinaDepartmentsSync.class.getResourceAsStream("es.txt"), "utf-8")),
            (WikiPageRetriever) ctx.getBean("httpWikiPageRetriever"), LangUtils.ES,
            (Closure) ctx.getBean("administrativeClosure"));
}

From source file:com.reversemind.glia.test.go3.java

public static void main(String... args) throws Exception {

    System.setProperty("http.proxyHost", "10.105.0.217");
    System.setProperty("http.proxyPort", "3128");

    System.setProperty("https.proxyHost", "10.105.0.217");
    System.setProperty("https.proxyPort", "3128");

    HttpHost proxy = new HttpHost("10.105.0.217", 3128);
    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

    HttpGet request = new HttpGet(
            "https://twitter.com/i/profiles/show/splix/timeline/with_replies?include_available_features=1&include_entities=1&max_id=285605679744569344");
    HttpResponse response = client.execute(request);

    // Get the response
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

    String sl = "";
    String line = "";
    while ((line = rd.readLine()) != null) {
        LOG.debug(line);/*from   w ww  .  j  ava  2 s .  c o  m*/
        sl += line;
    }

    sl = new String(sl.getBytes(), "UTF-8");
    String sss = sl.replaceAll("\\{1,}", "\\").replaceAll("\\\"", "'").replaceAll("\\"", "'")
            .replaceAll("&gt;", ">").replaceAll("&lt;", "<").replaceAll("&amp;", "&").replaceAll("&apos;", "'")
            .replaceAll("\u003c", "<").replaceAll("\u003e", ">").replaceAll("\n", " ").replaceAll("\\/", "/")
            .replaceAll("\\'", "'");

    String sss2 = sss.replaceAll("\\'", "'");
    LOG.debug(sss);

    save("/opt/_del/go_sl.txt", sl);
    save("/opt/_del/go_sss.txt", sss);
    save("/opt/_del/go_line.txt", line);
    save("/opt/_del/go_sss2.txt", sss2);

    LOG.debug("\n\n\n\n\n");
    LOG.debug(sss);
    LOG.debug("\n\n\n\n\n");
    LOG.debug(URLDecoder.decode(sl, "UTF-8"));
    LOG.debug(URLDecoder.decode("\u0438\u043d\u043e\u0433\u0434\u0430", "UTF-8"));

    LOG.debug(URLDecoder.decode("\n            \u003c/span\u003e\n            \u003cb\u003e\n ", "UTF-8"));

}

From source file:nl.minbzk.dwr.zoeken.enricher.Enricher.java

/**
 * Application entry-point./*from w  w w  .j  a  v a  2s .  co  m*/
 * 
 * @param args
 * @throws Exception
 */
public static void main(String[] args) throws Exception {
    try {
        ApplicationContext context = new ClassPathXmlApplicationContext(APPLICATION_CONTEXT);

        // Create a new enricher service

        EnricherService service = (EnricherService) context.getBean("enricherService");

        // Retrieve the fetcher settings

        EnricherSettings settings = (EnricherSettings) context.getBean("settings");

        if (!settings.processArguments(args))
            System.exit(-1);

        // We assume the input encoding is the same as the output encoding

        InputStreamReader reader = new InputStreamReader(new FileInputStream(settings.getInputFile()),
                settings.getEncoding());

        // Now process the given file

        service.processImport(reader, settings.getJobOverride(), settings.getEncoding());
    } catch (Exception e) {
        logger.error("The given import envelopes could not be processed", e);

        System.exit(1);
    }
}

From source file:com.adobe.aem.demomachine.Updates.java

public static void main(String[] args) {

    String rootFolder = null;// w w  w . ja va2 s .c  o m

    // Command line options for this tool
    Options options = new Options();
    options.addOption("f", true, "Demo Machine root folder");
    CommandLineParser parser = new BasicParser();
    try {
        CommandLine cmd = parser.parse(options, args);

        if (cmd.hasOption("f")) {
            rootFolder = cmd.getOptionValue("f");
        }

    } catch (Exception e) {
        System.exit(-1);
    }

    Properties md5properties = new Properties();

    try {
        URL url = new URL(
                "https://raw.githubusercontent.com/Adobe-Marketing-Cloud/aem-demo-machine/master/conf/checksums.properties");
        InputStream in = url.openStream();
        Reader reader = new InputStreamReader(in, "UTF-8");
        md5properties.load(reader);
        reader.close();
    } catch (Exception e) {
        System.out.println("Error: Cannot connect to GitHub.com to check for updates");
        System.exit(-1);
    }

    System.out.println(AemDemoConstants.HR);

    int nbUpdateAvailable = 0;

    List<String[]> listPaths = Arrays.asList(AemDemoConstants.demoPaths);
    for (String[] path : listPaths) {
        if (path.length == 5) {
            logger.debug(path[1]);
            File pathFolder = new File(rootFolder + (path[1].length() > 0 ? (File.separator + path[1]) : ""));
            if (pathFolder.exists()) {
                String newMd5 = AemDemoUtils.calcMD5HashForDir(pathFolder, Boolean.parseBoolean(path[3]),
                        false);
                logger.debug("MD5 is: " + newMd5);
                String oldMd5 = md5properties.getProperty("demo.md5." + path[0]);
                if (oldMd5 == null || oldMd5.length() == 0) {
                    logger.error("Cannot find MD5 for " + path[0]);
                    System.out.println(path[2] + " : Cannot find M5 checksum");
                    continue;
                }
                if (newMd5.equals(oldMd5)) {
                    continue;
                } else {
                    System.out.println(path[2] + " : New update available"
                            + (path[0].equals("0") ? " (use 'git pull' to get the latest changes)" : ""));
                    nbUpdateAvailable++;
                }
            } else {
                System.out.println(path[2] + " : Not installed");
            }
        }
    }

    if (nbUpdateAvailable == 0) {
        System.out.println("Your AEM Demo Machine is up to date!");
    }

    System.out.println(AemDemoConstants.HR);

}

From source file:UseConverters.java

public static void main(String[] args) {
    try {/*from   w  ww . j  ava  2s . c  o m*/
        BufferedReader fromKanji = new BufferedReader(
                new InputStreamReader(new FileInputStream("kanji.txt"), "EUC_JP"));
        PrintWriter toSwedish = new PrintWriter(new OutputStreamWriter( // XXX
                // check
                // enco
                new FileOutputStream("sverige.txt"), "ISO8859_3"));

        // reading and writing here...
        String line = fromKanji.readLine();
        System.out.println("-->" + line + "<--");
        toSwedish.println(line);
        fromKanji.close();
        toSwedish.close();
    } catch (UnsupportedEncodingException exc) {
        System.err.println("Bad encoding" + exc);
        return;
    } catch (IOException err) {
        System.err.println("I/O Error: " + err);
        return;
    }
}

From source file:com.leixl.easyframework.action.httpclient.TestHttpPost.java

public static void main(String[] args) {

    Map<String, Object> paramMap = new HashMap<String, Object>();
    paramMap.put("uid", 1);
    paramMap.put("desc",
            "?????");
    paramMap.put("payStatus", 1);

    //HttpConnUtils.postHttpContent(URL, paramMap);

    //HttpClient//from   www  .j a v a  2 s  .  c o  m
    HttpClient httpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(URL);
    // ??
    NameValuePair[] data = { new NameValuePair("uid", "1"),
            new NameValuePair("desc",
                    "?????"),
            new NameValuePair("payStatus", "1") };
    // ?postMethod
    postMethod.setRequestBody(data);
    // postMethod
    int statusCode;
    try {
        statusCode = httpClient.executeMethod(postMethod);
        if (statusCode == HttpStatus.SC_OK) {
            StringBuffer contentBuffer = new StringBuffer();
            InputStream in = postMethod.getResponseBodyAsStream();
            BufferedReader reader = new BufferedReader(
                    new InputStreamReader(in, postMethod.getResponseCharSet()));
            String inputLine = null;
            while ((inputLine = reader.readLine()) != null) {
                contentBuffer.append(inputLine);
                System.out.println("input line:" + inputLine);
                contentBuffer.append("/n");
            }
            in.close();

        } else if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
                || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
            // ???
            Header locationHeader = postMethod.getResponseHeader("location");
            String location = null;
            if (locationHeader != null) {
                location = locationHeader.getValue();
                System.out.println("The page was redirected to:" + location);
            } else {
                System.err.println("Location field value is null.");
            }
        }
    } catch (HttpException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.cncounter.test.httpclient.ProxyTunnelDemo.java

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

    ProxyClient proxyClient = new ProxyClient();
    HttpHost target = new HttpHost("www.google.com", 80);
    HttpHost proxy = new HttpHost("localhost", 1080);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd");
    Socket socket = proxyClient.tunnel(proxy, target, credentials);
    try {/*from  ww  w  . j av  a2 s .  com*/
        Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
        out.write("GET / HTTP/1.1\r\n");
        out.write("Host: " + target.toHostString() + "\r\n");
        out.write("Agent: whatever\r\n");
        out.write("Connection: close\r\n");
        out.write("\r\n");
        out.flush();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET));
        String line = null;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    } finally {
        socket.close();
    }
}

From source file:com.dlmu.heipacker.crawler.client.ProxyTunnelDemo.java

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

    ProxyClient proxyClient = new ProxyClient();
    HttpHost target = new HttpHost("www.yahoo.com", 80);
    HttpHost proxy = new HttpHost("localhost", 8888);
    UsernamePasswordCredentials credentials = new UsernamePasswordCredentials("user", "pwd");
    Socket socket = proxyClient.tunnel(proxy, target, credentials);
    try {//  w w w.  ja v  a2s. co  m
        Writer out = new OutputStreamWriter(socket.getOutputStream(), HTTP.DEF_CONTENT_CHARSET);
        out.write("GET / HTTP/1.1\r\n");
        out.write("Host: " + target.toHostString() + "\r\n");
        out.write("Agent: whatever\r\n");
        out.write("Connection: close\r\n");
        out.write("\r\n");
        out.flush();
        BufferedReader in = new BufferedReader(
                new InputStreamReader(socket.getInputStream(), HTTP.DEF_CONTENT_CHARSET));
        String line = null;
        while ((line = in.readLine()) != null) {
            System.out.println(line);
        }
    } finally {
        socket.close();
    }
}

From source file:ProcessorDemo.java

public static void main(String args[]) {
    try {/*  w  w w. j a v  a 2s  .  c  o m*/
        System.setProperty("sen.home", "../Sen1221/senhome-ipadic");
        System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
        System.setProperty("org.apache.commons.logging.simplelog.defaultlog", "FATAL");

        if (args.length != 2) {
            System.err.println("usage: java ProcessorDemo <filename> <encoding>");
            System.exit(1);
        }

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(args[0]), args[1]));
        String confPath = System.getProperty("sen.home") + System.getProperty("file.separator")
                + "conf/sen-processor.xml";
        StreamTagger tagger = new StreamTagger((Reader) br, confPath);
        readConfig(confPath);

        if (!isCompound) {
            CompoundWordPostProcessor cwProcessor = new CompoundWordPostProcessor(compoundFile);
            tagger.addPostProcessor(cwProcessor);
        }

        if (compositRule != null && !compositRule.equals("")) {
            CompositPostProcessor processor = new CompositPostProcessor();
            processor.readRules(new BufferedReader(new StringReader(compositRule)));
            tagger.addPostProcessor(processor);
        }

        if (remarkRule != null && !remarkRule.equals("")) {
            RemarkPreProcessor processor = new RemarkPreProcessor();
            processor.readRules(new BufferedReader(new StringReader(remarkRule)));
            tagger.addPreProcessor(processor);
            RemarkPostProcessor p2 = new RemarkPostProcessor();
            tagger.addPostProcessor(p2);
        }

        // BufferedReader is = new BufferedReader(System.in);

        while (tagger.hasNext()) {
            Token token = tagger.next();
            System.out.println(token.getSurface() + "\t" + token.getPos() + "\t" + token.start() + "\t"
                    + token.end() + "\t" + token.getCost() + "\t" + token.getAddInfo());
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
}