Example usage for java.io InputStream available

List of usage examples for java.io InputStream available

Introduction

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

Prototype

public int available() throws IOException 

Source Link

Document

Returns an estimate of the number of bytes that can be read (or skipped over) from this input stream without blocking, which may be 0, or 0 when end of stream is detected.

Usage

From source file:com.emc.ecs.sync.filter.ShellCommandFilter.java

private void drain(InputStream in, PrintStream out) throws IOException {
    while (in.available() > 0) {
        out.print((char) in.read());
    }//from w  ww . j  ava 2s .co m
}

From source file:org.im.message.service.InitCertTest.java

public void initAppCert() {
    try {/*from   w ww  .  j  a  va  2  s.  com*/
        AppCert cert = new AppCert();
        cert.setAppId("sfa");
        cert.setConnCount(10);
        cert.setProductionCertEnabled(false);

        InputStream devIs = InitCertTest.class.getResourceAsStream("/cert/tiaoshi.p12");
        byte[] bs = new byte[devIs.available()];
        devIs.read(bs);
        cert.setDevCert(bs);
        cert.setDevCertPwd("111111");

        InputStream productionIs = InitCertTest.class.getResourceAsStream("/cert/fabu.p12");
        byte[] bs2 = new byte[productionIs.available()];
        productionIs.read(bs2);
        cert.setProductionCert(bs2);
        cert.setProductionCertPwd("111111");

        devIs.close();
        productionIs.close();

        appCertDao.save(cert);
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:base.compilations.PascalCompilation.java

@Override
protected List<CompilationError> processStream(InputStream stream) throws IOException {

    System.out.println("stream: " + stream.available());

    List<CompilationError> errors = new ArrayList<>();
    System.out.println("???????????????????????????");
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(stream))) {
        String colonSymbol = ":";
        String errorKeyWord = "Error" + colonSymbol;
        String fatalKeyWord = "Fatal" + colonSymbol;
        String line = "";
        System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
        while ((line = reader.readLine()) != null) {
            System.out.println("before if----------");
            if (line.contains(fileExtention)) {
                System.out.println("aqanaaa--------------");
                if (line.contains(errorKeyWord)) {
                    CompilationError error = processLineFor(errorKeyWord, line);
                    errors.add(error);/*w w  w .  j a v a2 s. c  o  m*/
                } else if (line.contains(fatalKeyWord)) {
                    CompilationError syntaxFatal = processLineFor(fatalKeyWord, line);
                    errors.add(syntaxFatal);
                }
            }
        }
    }
    System.out.println("---------------");
    for (CompilationError error : errors) {
        System.out.println(error);
    }
    System.out.println("---------------");
    return errors;
}

From source file:mx.com.quadrum.contratos.controller.busquedas.MuestraPdf.java

@RequestMapping(value = "muestraPdf/{idContrato}", method = RequestMethod.GET)
public void muestraPdf(@PathVariable("idContrato") Integer idContrato, HttpSession session,
        HttpServletRequest request, HttpServletResponse response) {
    if (session.getAttribute(USUARIO) == null && session.getAttribute(CLIENTE) == null) {
        return;/* w ww .  j av a2 s. c om*/
    }
    Contrato contrato = contratoService.buscarPorId(idContrato);

    Usuario usuario = (Usuario) session.getAttribute(USUARIO);
    response.setContentType("application/pdf");

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    File pdf = new File(
            USUARIOS + usuario.getMail() + "\\" + contrato.getNombre() + "\\" + contrato.getNombre() + ".pdf");
    try {
        InputStream in = new FileInputStream(pdf);
        byte[] data = new byte[in.available()];
        in.read(data);
        javax.servlet.ServletOutputStream servletoutputstream = response.getOutputStream();

        servletoutputstream.write(data);
        servletoutputstream.flush();
        servletoutputstream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:mx.com.quadrum.contratos.controller.busquedas.MuestraPdf.java

@RequestMapping(value = "muestraPdf/{idContrato}/{idEmpleado}", method = RequestMethod.GET)
public void muestraPdf(@PathVariable("idContrato") Integer idContrato,
        @PathVariable("idEmpleado") Integer idEmpleado, HttpSession session, HttpServletRequest request,
        HttpServletResponse response) {/*ww w .j  ava  2s  .c om*/

    if (session.getAttribute(USUARIO) == null && session.getAttribute(CLIENTE) == null) {
        return;
    }
    Contrato contrato = contratoService.buscarPorId(idContrato);
    response.setContentType("application/pdf");

    response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    Usuario usuario = usuarioService.buscarPorId(idEmpleado);
    File pdf = new File(
            USUARIOS + usuario.getMail() + "\\" + contrato.getNombre() + "\\" + contrato.getNombre() + ".pdf");
    try {
        InputStream in = new FileInputStream(pdf);
        byte[] data = new byte[in.available()];
        in.read(data);
        javax.servlet.ServletOutputStream servletoutputstream = response.getOutputStream();

        servletoutputstream.write(data);
        servletoutputstream.flush();
        servletoutputstream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:net.peterkuterna.android.apps.devoxxsched.io.LocalExecutor.java

public void execute(Context context, String assetName, JSONHandler handler) throws JSONHandlerException {
    try {//from   w w  w  .  j a  v a 2  s .  c o  m
        final InputStream input = context.getAssets().open(assetName);
        byte[] buffer = new byte[input.available()];
        while (input.read(buffer) != -1)
            ;
        String jsontext = new String(buffer);
        ArrayList<JSONArray> entries = Lists.newArrayList();
        entries.add(new JSONArray(jsontext));
        handler.setLocalSync(true);
        handler.parseAndApply(entries, mResolver);
    } catch (JSONHandlerException e) {
        throw e;
    } catch (JSONException e) {
        throw new JSONHandlerException("Problem parsing local asset: " + assetName, e);
    } catch (IOException e) {
        throw new JSONHandlerException("Problem parsing local asset: " + assetName, e);
    }
}

From source file:com.anosym.webcmd.web.SSHTerminalController.java

@SuppressWarnings({ "UseSpecificCatch", "BroadCatchBlock", "TooBroadCatch" })
public void handleCommand() {
    try {//from  ww w . j  a  v a  2s  . c o  m
        String command = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap()
                .get("ssh-terminal-command");
        String cmd[] = command.trim().split(" ");
        System.out.println("Command: " + Arrays.toString(cmd));
        Process p = Runtime.getRuntime().exec(cmd);
        p.waitFor();
        InputStream inn = p.getInputStream();
        int count = inn.available();
        byte[] buffer = new byte[count];
        //wait for the input to be available.
        inn.read(buffer);
        //            String result = new String(buffer);
        //            SSHTerminalResponse response = new SSHTerminalResponse(result, SSHTerminalResponse.TerminalResponseType.COMPLETE);
        //            RequestContext rc = RequestContext.getCurrentInstance();
        //            rc.addCallbackParam("response", response);
        //            System.out.println("Response: " + result);
    } catch (Exception ex) {
        //            Logger.getLogger(SSHTerminalController.class.getName()).log(Level.SEVERE, null, ex);
        //            String result = ExceptionUtils.getFullStackTrace(ex);
        //            SSHTerminalResponse response = new SSHTerminalResponse(result, SSHTerminalResponse.TerminalResponseType.COMPLETE);
        //            RequestContext rc = RequestContext.getCurrentInstance();
        //            rc.addCallbackParam("response", response);
    }

}

From source file:com.github.mrstampy.gameboot.GameBootDependencyWriter.java

private void writeResource(Resource resource) throws IOException {
    String desc = resource.getDescription();
    log.debug("Creating file from {}", desc);

    if (!resource.exists()) {
        log.warn("No resource for {}", desc);
        return;//from w  ww.ja  va  2  s . c om
    }

    int first = desc.indexOf("[");
    int last = desc.indexOf("]");

    desc = desc.substring(first + 1, last);

    File f = new File(".", desc);

    try (BufferedOutputStream bis = new BufferedOutputStream(new FileOutputStream(f))) {
        InputStream in = resource.getInputStream();
        byte[] b = new byte[in.available()];
        in.read(b);

        bis.write(b);
        bis.flush();
    }
}

From source file:org.musa.payload.MechanicusTeleportReceiver.java

private String readString(InputStream in) throws IOException {
    StringBuilder sb = new StringBuilder();

    int val;
    while (in.available() > 0) {

        //in.//from  w ww.  j  a va2s  .c o  m
        val = in.read();

        if (((char) val) == ';' || val == -1)
            break;

        sb.append((char) val);
    }

    //System.out.println("string == " +sb.toString());
    return sb.toString();
}

From source file:net.sf.sail.webapp.dao.sds.impl.AbstractHttpRestCommand.java

private void logResponse(InputStream responseStream) throws IOException {
    byte[] responseBuffer = new byte[responseStream.available()];
    responseStream.read(responseBuffer);
    logger.debug(new String(responseBuffer));
    responseStream.reset();/*from   w w  w.j av a  2  s.c  om*/
}