Example usage for java.io InputStream toString

List of usage examples for java.io InputStream toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a string representation of the object.

Usage

From source file:com.ibm.mobilefirst.mobileedge.recordapp.TestingActivity.java

private void loadAllGestures() {
    ArrayList<InputStream> savedGesturesAsInputStream = GesturesDataUtils.getEnabledGesturesAsInputStream(this);

    for (InputStream is : savedGesturesAsInputStream) {
        classification.loadGesture(is);/*  w w  w . j ava2 s .  c  o  m*/
        Log.v("TestingActivity", "Loaded gesture == " + is.toString());

        //            try {
        //                is.close();              //No need to close it, the BufferedReader will close it by itself.
        //            } catch (IOException e) {
        //                e.printStackTrace();
        //            }
    }
}

From source file:com.ifeng.vdn.ip.repository.service.impl.AliBatchIPAddressChecker.java

@Override
public List<AliIPBean> check(List<String> ips) {

    List<AliIPBean> list = new ArrayList<AliIPBean>();

    AliIPBean ipaddress = null;// ww  w . jav a2s  .  co m
    String url = "http://ip.taobao.com/service/getIpInfo2.php";

    for (String ip : ips) {

        // Create an instance of HttpClient.
        HttpClient clinet = new HttpClient();

        // Create a method instance.
        PostMethod postMethod = new PostMethod(url);

        // Execute the method.
        try {
            postMethod.setParameter("ip", ip);
            int resultCode = clinet.executeMethod(postMethod);

            if (resultCode == HttpStatus.SC_OK) {
                // Read the response body.
                InputStream responseBody = postMethod.getResponseBodyAsStream();

                ObjectMapper mapper = new ObjectMapper();
                ipaddress = mapper.readValue(responseBody, AliIPBean.class);

                log.info(responseBody.toString());

                list.add(ipaddress);
            } else {
                list.add(new AliIPBean());
                log.error("Method failedd: [{}] , IP: [{}]", postMethod.getStatusCode(), ip);
            }

        } catch (JsonParseException | JsonMappingException | HttpException e) {
            list.add(new AliIPBean());
            log.error(e.getMessage(), e);
        } catch (IOException e) {
            list.add(new AliIPBean());
            log.error(e.getMessage(), e);
        }
    }
    return list;
}

From source file:com.ifeng.vdn.ip.repository.service.impl.AliIPAddressChecker.java

public IPAddress ipCheckByGet(String ip) {
    AliIPBean ipaddress = null;// w w  w.ja v a 2  s .c o  m

    String url = "http://ip.taobao.com/service/getIpInfo.php?ip=" + ip;

    // Create an instance of HttpClient.
    HttpClient clinet = new HttpClient();

    // Create a method instance.
    GetMethod getMethod = new GetMethod(url);

    // Execute the method.
    // Read the response body.
    try {

        int resultCode = clinet.executeMethod(getMethod);

        if (resultCode == HttpStatus.SC_OK) {
            InputStream responseBody = getMethod.getResponseBodyAsStream();

            ObjectMapper mapper = new ObjectMapper();
            ipaddress = mapper.readValue(responseBody, AliIPBean.class);

            log.info(responseBody.toString());
        } else {
            log.error("Method failedd: [{}] , IP: [{}]", getMethod.getStatusCode(), ip);
        }

    } catch (JsonParseException | JsonMappingException | HttpException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    return ipaddress;
}

From source file:com.ifeng.vdn.ip.repository.service.impl.AliIPAddressChecker.java

@Override
public IPAddress ipcheck(String ip) {
    AliIPBean ipaddress = null;/*www .ja v  a  2s  . com*/

    String url = "http://ip.taobao.com/service/getIpInfo2.php";

    // Create an instance of HttpClient.
    HttpClient clinet = new HttpClient();

    // Create a method instance.
    PostMethod postMethod = new PostMethod(url);

    // Execute the method.
    // Read the response body.
    try {

        postMethod.setParameter("ip", ip);

        int resultCode = clinet.executeMethod(postMethod);

        if (resultCode == HttpStatus.SC_OK) {
            InputStream responseBody = postMethod.getResponseBodyAsStream();

            ObjectMapper mapper = new ObjectMapper();
            ipaddress = mapper.readValue(responseBody, AliIPBean.class);

            log.info(responseBody.toString());
        } else {
            log.error("Method failedd: [{}] , IP: [{}]", postMethod.getStatusCode(), ip);
        }

    } catch (JsonParseException | JsonMappingException | HttpException e) {
        log.error(e.getMessage(), e);
    } catch (IOException e) {
        log.error(e.getMessage(), e);
    }

    return ipaddress;
}

From source file:net.fizzl.redditengine.impl.UserApi.java

/**
 * Checks if a username is available for registration
 * /* ww  w. ja  v  a 2s.  c  o  m*/
 * @param user   username to be checked
 * @return true or false
 * @throws RedditEngineException
 */
public boolean isUsernameAvailable(String user) throws RedditEngineException {
    StringBuilder path = new StringBuilder();
    path.append(UrlUtils.BASE_URL);
    path.append("/api/username_available.json");
    String url = path.toString();

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("user", user));

    SimpleHttpClient client = SimpleHttpClient.getInstance();
    boolean isAvailable = false;
    try {
        InputStream is = client.get(url, params);
        isAvailable = Boolean.valueOf(is.toString());
        is.close();
    } catch (Exception e) {
        RedditEngineException re = new RedditEngineException(e);
        throw re;
    }
    return isAvailable;
}

From source file:org.duracloud.chunk.writer.FilesystemContentWriter.java

private void copy(InputStream chunk, OutputStream outStream) {
    try {/*from  ww w.j  a va2s .co m*/
        IOUtils.copy(chunk, outStream);
    } catch (IOException e) {
        String msg = "Error in copy: " + chunk.toString() + ": ";
        log.error(msg, e);
        throw new DuraCloudRuntimeException(msg + e.getMessage(), e);
    }
}

From source file:org.duracloud.chunk.writer.FilesystemContentWriter.java

private void copyLarge(InputStream chunk, OutputStream outStream) {
    try {/*from   w  w w .j  a  va 2 s . c  o  m*/
        IOUtils.copyLarge(chunk, outStream);
    } catch (IOException e) {
        String msg = "Error in copy: " + chunk.toString() + ": ";
        log.error(msg, e);
        throw new DuraCloudRuntimeException(msg + e.getMessage(), e);
    }
}

From source file:io.milton.s3.controller.AmazonS3Controller.java

@PutChild
public File createFile(Folder parent, String newName, InputStream inputStream, Long contentLength,
        String contentType) {/*from  w  ww.  j a  v a 2  s  .  c  o  m*/
    LOG.info("Creating file " + inputStream.toString() + " with name " + newName + " in the folder "
            + parent.getName() + " in bucket " + BUCKET_NAME);

    // Create a file and store into Amazon Simple Storage Service
    File newFile = parent.addFile(newName);
    newFile.setSize(contentLength);
    // Get default content type if cannot get via milton
    if (StringUtils.isEmpty(contentType)) {
        contentType = new MimetypesFileTypeMap(inputStream).getContentType(newName);
    }
    newFile.setContentType(contentType);

    LOG.info("Successfully created file " + newName + " [name=" + newName + ", contentLength=" + contentLength
            + ", contentType=" + contentType + "] in bucket " + BUCKET_NAME);
    boolean isCreatedFile = amazonStorageService.putEntity(BUCKET_NAME, newFile, inputStream);
    if (!isCreatedFile) {
        LOG.error("Could not create file " + newName + " in bucket " + BUCKET_NAME);
        throw new RuntimeException("Could not create file " + newName + " in bucket " + BUCKET_NAME);
    }
    LOG.warn("Successfully created file " + newName + " under folder " + parent + " in bucket " + BUCKET_NAME);
    return newFile;
}

From source file:com.maverick.util.IOStreamConnector.java

/**
 *
 *
 * @param in/*from w w  w. j  a va  2  s .  co  m*/
 * @param out
 */
public void connect(InputStream in, OutputStream out) {
    this.in = in;
    this.out = out;

    thread = new Thread(new IOStreamConnectorThread());
    thread.setDaemon(true);
    thread.setName("IOStreamConnector " + in.toString() + ">>" + out.toString());
    thread.start();
}

From source file:org.kitodo.production.plugin.opac.pica.GetOpac.java

/**
 * Helper method that parses an InputSource and returns a DOM Document.
 *
 * @param source//from w w w.  ja  v a 2 s  .  c om
 *            The InputSource to parse
 * @return The resulting document
 */
private Document getParsedDocument(InputSource source) {
    try {
        return this.docBuilder.parse(source);
    } catch (SAXException e) {
        logger.info("Dokument?");

        InputStream bs = source.getByteStream();

        logger.info(bs.toString());
        e.printStackTrace();

    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}