Example usage for java.io StringBufferInputStream StringBufferInputStream

List of usage examples for java.io StringBufferInputStream StringBufferInputStream

Introduction

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

Prototype

public StringBufferInputStream(String s) 

Source Link

Document

Creates a string input stream to read data from the specified string.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new PropertyResourceBundle(propStream);

    // Get resource keys
    Enumeration keys = bundle.getKeys();
    while (keys.hasMoreElements()) {
        System.out.println("Bundle key: " + keys.nextElement());
    }//from   w w w  .  j  a  va 2 s  . com
}

From source file:Main.java

public static void main(String[] args) throws IOException {
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913";
    InputStream propStream = new StringBufferInputStream(fileContent);

    PropertyResourceBundle bundle = new Main(propStream);

    // Get resource key set
    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
        System.out.println("Bundle key: " + keys.next());
    }/*  ww  w  . j av  a2 s  .  co  m*/

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    // Prepare content for simulating property files
    String fileContent = "s1=1\n" + "s2=Main\n" + "s3=Fri Jan 31 00:00:00 IST 3913";
    InputStream propStream = new StringBufferInputStream(fileContent);

    // Create property resource bundle
    PropertyResourceBundle bundle = new Main(propStream);

    // Get resource key set
    Set keySet = bundle.handleKeySet();
    Iterator keys = keySet.iterator();
    while (keys.hasNext()) {
        System.out.println("Bundle key: " + keys.next());
    }//from   ww  w .j  a  v  a  2  s. c  o m

}

From source file:Main.java

public static Document parse(String s) throws SAXException, IOException {
    return parse(new StringBufferInputStream(s));
}

From source file:Main.java

private static Document getCurrentstudents() throws Exception {
    DocumentBuilder builder = dbFactory.newDocumentBuilder();
    Document docstudent = builder.parse(new StringBufferInputStream(studentData));
    return docstudent;
}

From source file:Main.java

private static Element getNewstudent() throws Exception {
    DocumentBuilder builder = dbFactory.newDocumentBuilder();
    Document newstudent = builder.parse(new StringBufferInputStream(studentData));
    Element student = newstudent.getDocumentElement();
    return student;
}

From source file:MyServlet.java

public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
    try {//from  w  ww  .ja v a 2s.  c  o m
        res.setContentType("text/plain; charset=UTF-8");
        PrintWriter out = res.getWriter();

        String charset = req.getParameter("charset");

        String text = req.getParameter("text");

        BufferedReader reader = new BufferedReader(
                new InputStreamReader(new StringBufferInputStream(text), charset));
        text = reader.readLine();

        out.println("Received charset: " + charset);
        out.println("Received text: " + text);
        out.println("Received text (escaped): " + toUnicodeEscapeString(text));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.github.rwhogg.git_vcr.UtilTest.java

/**
 * Test getFilesChanged//  w w w  .  j av a 2s.c o  m
 */
@SuppressWarnings("deprecation")
public void testGetFilesChanged() throws IOException {
    // empty diff
    Patch patch = new Patch();
    assertEquals(Util.getFilesChanged(patch).size(), 0);

    // with files
    patch.parse(new StringBufferInputStream(patchText));
    String[] expectedResults = { "file1", "file2", "file3" };
    List<ImmutablePair<String, String>> results = Util.getFilesChanged(patch);
    for (int i = 0; i < expectedResults.length; i++) {
        ImmutablePair<String, String> result = results.get(i);
        String leftResult = result.left;
        assertEquals(leftResult, result.right);
        assertEquals(leftResult, expectedResults[i]);
    }
}

From source file:org.eclipse.virgo.ide.management.remote.StandardBundleAdmin.java

@ManagedOperation(description = "Executes the given command")
public String execute(String cmdLine) {
    @SuppressWarnings("deprecation")
    StringBufferInputStream in = new StringBufferInputStream("");
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    PrintStream out = new PrintStream(output);

    try {/*  w w  w  .j  a va 2  s  .  c  o  m*/
        CommandProcessor commandProcessor = this.commandProcessorTracker.getService();
        if (commandProcessor != null) {
            CommandSession commandSession = commandProcessor.createSession(in, out, out);
            Object result = null;
            try {
                result = commandSession.execute(cmdLine);
            } catch (Exception e) {
                e.printStackTrace(out);
                return output.toString();
            }
            if (result == null) {
                result = "";
            }
            return output.toString() + "\n" + result.toString();
        }
        return "No CommandProcessor registered; cannot execute commands";
    } finally {
        try {
            out.close();
            output.close();
        } catch (IOException e) {
        }
    }
}

From source file:com.tremolosecurity.proxy.filter.PostProcess.java

protected void postProcess(HttpFilterRequest req, HttpFilterResponse resp, UrlHolder holder,
        HttpResponse response, String finalURL, HttpFilterChain curChain, HttpRequestBase httpRequest)
        throws IOException, Exception {
    boolean isText;
    HttpEntity entity = null;//  ww  w.  jav a2  s. com

    try {
        entity = response.getEntity();
        /*if (entity != null) {
            entity = new BufferedHttpEntity(entity);
        }*/
    } catch (Throwable t) {
        throw new Exception(t);
    }

    InputStream ins = null;
    boolean entExists = false;

    if (entity == null) {
        resp.setStatus(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase());
        ins = new StringBufferInputStream("");
    } else {
        try {
            ins = entity.getContent();
            resp.setStatus(response.getStatusLine().getStatusCode(),
                    response.getStatusLine().getReasonPhrase());
            entExists = true;
        } catch (IllegalStateException e) {
            //do nothing
        }
    }

    if (entExists) {
        org.apache.http.Header hdr = response.getFirstHeader("Content-Type");
        org.apache.http.Header encoding = response.getFirstHeader("Content-Encoding");

        /*if (hdr == null) {
           isText = false;
        } else {
           isText = response.getFirstHeader("Content-Type").getValue().startsWith("text");
                   
           if (encoding != null ) {
              isText = (! encoding.getValue().startsWith("gzip")) && (! encoding.getValue().startsWith("deflate"));
           }
                   
           if (isText) {
              resp.setContentType(response.getFirstHeader("Content-Type").getValue());
              resp.setLocale(response.getLocale());
           }
        }*/
        isText = false;

        try {
            resp.setCharacterEncoding(null);
        } catch (Throwable t) {
            //we're not doing anything
        }

        StringBuffer stmp = new StringBuffer();
        if (response.getFirstHeader("Content-Type") != null) {
            resp.setContentType(response.getFirstHeader("Content-Type").getValue());
        }

        if (response.getLocale() != null) {
            resp.setLocale(response.getLocale());
        }

        org.apache.http.Header[] headers = response.getAllHeaders();
        for (int i = 0; i < headers.length; i++) {
            org.apache.http.Header header = headers[i];
            if (header.getName().equals("Content-Type")) {

                continue;
            } else if (header.getName().equals("Content-Type")) {

                continue;
            } else if (header.getName().equals("Content-Length")) {
                if (!header.getValue().equals("0")) {
                    continue;
                }
            } else if (header.getName().equals("Transfer-Encoding")) {
                continue;
            } else if (header.getName().equalsIgnoreCase("set-cookie")
                    || header.getName().equalsIgnoreCase("set-cookie2")) {
                //System.out.println(header.getValue());
                String cookieVal = header.getValue();
                /*if (cookieVal.endsWith("HttpOnly")) {
                   cookieVal = cookieVal.substring(0,cookieVal.indexOf("HttpOnly"));
                }
                        
                //System.out.println(cookieVal);*/

                List<HttpCookie> cookies = HttpCookie.parse(cookieVal);
                Iterator<HttpCookie> it = cookies.iterator();
                while (it.hasNext()) {
                    HttpCookie cookie = it.next();
                    String cookieFinalName = cookie.getName();
                    if (cookieFinalName.equalsIgnoreCase("JSESSIONID")) {
                        stmp.setLength(0);
                        stmp.append("JSESSIONID").append('-')
                                .append(holder.getApp().getName().replaceAll(" ", "|"));
                        cookieFinalName = stmp.toString();
                    }
                    Cookie respcookie = new Cookie(cookieFinalName, cookie.getValue());
                    respcookie.setComment(cookie.getComment());
                    if (cookie.getDomain() != null) {
                        respcookie.setDomain(cookie.getDomain());
                    }

                    if (cookie.hasExpired()) {
                        respcookie.setMaxAge(0);
                    } else {
                        respcookie.setMaxAge((int) cookie.getMaxAge());
                    }
                    respcookie.setPath(cookie.getPath());

                    respcookie.setSecure(cookie.getSecure());
                    respcookie.setVersion(cookie.getVersion());
                    resp.addCookie(respcookie);
                }
            } else if (header.getName().equals("Location")) {

                if (holder.isOverrideHost()) {
                    fixRedirect(req, resp, finalURL, header);
                } else {
                    resp.addHeader("Location", header.getValue());
                }
            } else {
                resp.addHeader(header.getName(), header.getValue());
            }

        }

        curChain.setIns(ins);
        curChain.setText(isText);
        curChain.setEntity(entity);
        curChain.setHttpRequestBase(httpRequest);

        //procData(req, resp, holder, isText, entity, ins);

    } else {
        isText = false;
    }
}