Java Examples for java.io.InputStream

The following java examples will help you to understand the usage of java.io.InputStream. These source code samples are taken from different open source projects.

Example 1
Project: jdroid-master  File: ParseCommand.java View source code
@Override
protected Object doExecute(InputStream inputStream) throws IOException {
    try {
        return parser.parse(inputStream);
    } catch (UnexpectedException e) {
        Throwable throwable = e.getCause();
        if (throwable instanceof IOException) {
            throw (IOException) throwable;
        } else {
            throw e;
        }
    }
}
Example 2
Project: extFM-Tooling-master  File: MtextStreamUtil.java View source code
public static String getContent(java.io.InputStream inputStream) throws java.io.IOException {
    StringBuffer content = new StringBuffer();
    java.io.InputStreamReader reader = new java.io.InputStreamReader(inputStream);
    int next = -1;
    while ((next = reader.read()) >= 0) {
        content.append((char) next);
    }
    return content.toString();
}
Example 3
Project: openjdk-master  File: DataFlavorComparatorTest1.java View source code
public static void main(String[] args) throws Exception {
    String[] mimes = new String[] { "text/plain;class=java.nio.ByteBuffer;charset=UTF-8", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-8", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16LE", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16LE", "application/x-java-text-encoding", "application/x-java-serialized-object;class=java.lang.String", "text/plain;class=java.io.InputStream;charset=UTF-8", "text/uri-list;class=java.io.InputStream;charset=UTF-8", "text/plain;class=java.io.InputStream;charset=windows-1252", "text/uri-list;class=java.io.InputStream;charset=windows-1252", "application/x-java-url;class=java.net.URL", "text/plain;class=java.io.Reader", "text/plain;charset=windows-1252", "text/uri-list;class=java.io.Reader", "text/uri-list;charset=windows-1252", "text/plain;charset=UTF-8", "text/uri-list;charset=UTF-8", "text/plain;class=java.io.InputStream;charset=US-ASCII", "text/uri-list;class=java.io.InputStream;charset=US-ASCII", "text/plain;class=java.io.InputStream;charset=UTF-16LE", "text/plain;charset=US-ASCII", "text/uri-list;class=java.io.InputStream;charset=UTF-16LE", "text/uri-list;charset=US-ASCII", "text/plain;charset=UTF-16LE", "text/uri-list;charset=UTF-16LE", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16BE", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16BE", "text/plain;class=java.nio.ByteBuffer;charset=ISO-8859-1", "text/uri-list;class=java.nio.ByteBuffer;charset=ISO-8859-1", "text/plain", "text/uri-list", "text/plain;class=java.nio.ByteBuffer;charset=UTF-16", "text/uri-list;class=java.nio.ByteBuffer;charset=UTF-16", "text/plain;class=java.io.InputStream;charset=unicode", "text/uri-list;class=java.io.InputStream;charset=UTF-16", "text/plain;class=java.nio.CharBuffer", "text/uri-list;class=java.nio.CharBuffer", "text/plain;class=java.lang.String", "text/plain;charset=UTF-16BE", "text/uri-list;class=java.lang.String", "text/uri-list;charset=UTF-16BE", "text/plain;charset=ISO-8859-1", "text/uri-list;charset=ISO-8859-1", "text/plain;class=java.io.InputStream;charset=UTF-16BE", "text/uri-list;class=java.io.InputStream;charset=UTF-16BE", "text/plain;class=java.nio.ByteBuffer;charset=US-ASCII", "text/uri-list;class=java.nio.ByteBuffer;charset=US-ASCII", "text/plain;class=java.io.InputStream;charset=ISO-8859-1", "text/uri-list;class=java.io.InputStream;charset=ISO-8859-1", "text/plain;charset=UTF-16", "text/plain;class=java.nio.ByteBuffer;charset=windows-1252", "text/uri-list;charset=UTF-16", "text/uri-list;class=java.nio.ByteBuffer;charset=windows-1252", "text/plain;class=java.io.InputStream;charset=windows-1252", "text/uri-list;class=java.io.InputStream;charset=windows-1252" };
    DataFlavor[] flavors = new DataFlavor[mimes.length];
    for (int i = 0; i < flavors.length; i++) {
        flavors[i] = new DataFlavor(mimes[i]);
    }
    testComparator(DataFlavorUtil.getDataFlavorComparator(), flavors);
    System.out.println("Passed.");
}
Example 4
Project: ARKOST-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 5
Project: SecurePhoto-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 6
Project: CareAndroid-master  File: StreamTool.java View source code
public static String inputStreamToString(InputStream in) throws Exception {
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    byte[] data = new byte[BUFFER_SIZE];
    int count = -1;
    while ((count = in.read(data, 0, BUFFER_SIZE)) != -1) outStream.write(data, 0, count);
    data = null;
    return new String(outStream.toByteArray(), "ISO-8859-1");
}
Example 7
Project: OrderNowAndroid-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 8
Project: android-ssl-master  File: IOUtil.java View source code
public static String readFully(InputStream inputStream) throws IOException {
    if (inputStream == null) {
        return "";
    }
    BufferedInputStream bufferedInputStream = null;
    ByteArrayOutputStream byteArrayOutputStream = null;
    try {
        bufferedInputStream = new BufferedInputStream(inputStream);
        byteArrayOutputStream = new ByteArrayOutputStream();
        final byte[] buffer = new byte[1024];
        int available = 0;
        while ((available = bufferedInputStream.read(buffer)) >= 0) {
            byteArrayOutputStream.write(buffer, 0, available);
        }
        return byteArrayOutputStream.toString();
    } finally {
        if (bufferedInputStream != null) {
            bufferedInputStream.close();
        }
    }
}
Example 9
Project: korsakow-editor-master  File: PipedExternalSoundEncoder.java View source code
public void encode(InputStream sourceStream, SoundFormat destFormat, OutputStream destStream) throws EncoderException {
    Process process = null;
    try {
        process = createProcess(destFormat);
    } catch (IOException e) {
        throw new SoundEncoderException(e);
    }
    encode(process, sourceStream, destStream);
}
Example 10
Project: Desktop-master  File: IOTools.java View source code
public static final String getStringFromStream(InputStream is, String charsetName) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(is, charsetName));
    StringBuilder sb = new StringBuilder();
    String line;
    while ((line = br.readLine()) != null) {
        sb.append(line + System.getProperty("line.separator"));
    }
    br.close();
    return sb.toString();
}
Example 11
Project: ocr-tools-master  File: Merger.java View source code
public void mergeBuffered(List<InputStream> inputs, OutputStream output) throws IOException {
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(output, 8 * 1024);
    try {
        merge(inputs, bufferedOutput);
    } finally {
        bufferedOutput.flush();
        bufferedOutput.close();
    }
}
Example 12
Project: aws-sdk-android-master  File: DigestValidationInputStream.java View source code
private void validateMD5Digest() {
    /*
         * Some InputStream readers (e.g., java.util.Properties) read more than
         * once at the end of the stream. This class validates the digest once
         * -1 has been read so we must not validate twice.
         */
    if (expectedHash != null && !digestValidated) {
        digestValidated = true;
        if (!Arrays.equals(digest.digest(), expectedHash)) {
            throw new AmazonClientException("Unable to verify integrity of data download.  " + "Client calculated content hash didn't match hash calculated by Amazon S3.  " + "The data may be corrupt.");
        }
    }
}
Example 13
Project: oobd-master  File: JcePasswordEnvelopedRecipient.java View source code
public RecipientOperator getRecipientOperator(AlgorithmIdentifier keyEncryptionAlgorithm, final AlgorithmIdentifier contentEncryptionAlgorithm, byte[] derivedKey, byte[] encryptedContentEncryptionKey) throws CMSException {
    Key secretKey = extractSecretKey(keyEncryptionAlgorithm, contentEncryptionAlgorithm, derivedKey, encryptedContentEncryptionKey);
    final Cipher dataCipher = helper.createContentCipher(secretKey, contentEncryptionAlgorithm);
    return new RecipientOperator(new InputDecryptor() {

        public AlgorithmIdentifier getAlgorithmIdentifier() {
            return contentEncryptionAlgorithm;
        }

        public InputStream getInputStream(InputStream dataOut) {
            return new CipherInputStream(dataOut, dataCipher);
        }
    });
}
Example 14
Project: android-platform-tools-base-master  File: Lib1.java View source code
public static String getContent() {
    InputStream input = Lib1.class.getResourceAsStream("Lib1.txt");
    if (input == null) {
        return "FAILED TO FIND Lib1.txt";
    }
    BufferedReader reader = null;
    try {
        reader = new BufferedReader(new InputStreamReader(input, "UTF-8"));
        return reader.readLine();
    } catch (IOException e) {
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (IOException e) {
            }
        }
    }
    return "FAILED TO READ CONTENT";
}
Example 15
Project: jeql-master  File: IOUtil.java View source code
public static String readTextFile(String srcName, boolean addEOL) throws IOException {
    InputSource inputSrc = new InputSource(srcName);
    StringBuffer buf = new StringBuffer();
    BufferedReader bufReader = null;
    try {
        InputStream inStream = inputSrc.createStream();
        bufReader = new BufferedReader(new InputStreamReader(inStream));
        String line = "";
        while ((line = bufReader.readLine()) != null) {
            buf.append(line);
            // possibly add EOL char to each line
            if (addEOL)
                buf.append('\n');
        }
    // System.out.println(buf);
    } finally {
        if (bufReader != null)
            bufReader.close();
    }
    // may be empty string if an error occurred
    return buf.toString();
}
Example 16
Project: Yarrn-master  File: SslCertificateHelper.java View source code
public static void trustGeotrustCertificate(final Context context) {
    try {
        final KeyStore trustStore = KeyStore.getInstance("BKS");
        final InputStream in = context.getResources().openRawResource(R.raw.geotrust_cert);
        trustStore.load(in, null);
        final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(trustStore);
        final SSLContext sslCtx = SSLContext.getInstance("TLS");
        sslCtx.init(null, tmf.getTrustManagers(), new java.security.SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sslCtx.getSocketFactory());
    } catch (final Exception e) {
        AQUtility.report(e);
        e.printStackTrace();
    }
}
Example 17
Project: TestingStuff-master  File: ImageUtils.java View source code
public static void copyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 18
Project: SideScrollerGDW2012-Max-master  File: CompositeImageData.java View source code
/**
	 * @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
	 */
public ByteBuffer loadImage(InputStream is, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException {
    CompositeIOException exception = new CompositeIOException();
    ByteBuffer buffer = null;
    BufferedInputStream in = new BufferedInputStream(is, is.available());
    in.mark(is.available());
    // cycle through our source until one of them works
    for (int i = 0; i < sources.size(); i++) {
        in.reset();
        try {
            LoadableImageData data = (LoadableImageData) sources.get(i);
            buffer = data.loadImage(in, flipped, forceAlpha, transparent);
            picked = data;
            break;
        } catch (Exception e) {
            Log.warn(sources.get(i).getClass() + " failed to read the data", e);
            exception.addException(e);
        }
    }
    if (picked == null) {
        throw exception;
    }
    return buffer;
}
Example 19
Project: polly-master  File: SilentStreamHandler.java View source code
@Override
protected void handle(InputStream stream) throws Exception {
    Reader reader = new InputStreamReader(stream);
    char[] buffer = new char[1024];
    while (reader.read(buffer) > 0) {
        if (this.isInterrupted()) {
            throw new InterruptedException();
        }
    }
}
Example 20
Project: TFC2-master  File: JSONReader.java View source code
public boolean read(File file) {
    try {
        Gson gson = new Gson();
        InputStream stream;
        if (file == null)
            stream = this.getClass().getResourceAsStream(path);
        else if (file.exists()) {
            stream = Files.asByteSource(file).openStream();
        } else {
            return false;
        }
        InputStreamReader sr = new InputStreamReader(stream);
        JsonReader reader = new JsonReader(sr);
        process(reader);
        reader.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return true;
}
Example 21
Project: tapestry-facebook-master  File: Channel.java View source code
Object onActivate() {
    return new StreamResponse() {

        public String getContentType() {
            return "text/html";
        }

        public InputStream getStream() throws IOException {
            return new ByteArrayInputStream(response.getBytes());
        }

        public void prepareResponse(Response response) {
            Date date = new Date();
            response.setDateHeader("Expires", date.getTime() + (maxAge * 1000));
            response.setHeader("Cache-Control", "max-age=" + maxAge);
            response.setHeader("Pragma", "public");
        }
    };
}
Example 22
Project: solmix-master  File: Version.java View source code
/**
     * @param groupId
     * @param artifactId
     * @return return special version
     */
public static String readFromMaven(String groupId, String artifactId) {
    String propPath = "/META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties";
    InputStream is = Version.class.getResourceAsStream(propPath);
    if (is != null) {
        Properties properties = new Properties();
        try {
            properties.load(is);
            String version = properties.getProperty("version");
            if (version != null) {
                return version;
            }
        } catch (IOException e) {
        } finally {
            IOUtils.closeQuitely(is);
        }
    }
    return "undetermined (please report this as bug)";
}
Example 23
Project: download-manager-master  File: RegularDataTransferer.java View source code
@Override
public DownloadTask.State transferData(DownloadTask.State state, InputStream in) throws StopRequestException {
    DownloadTask.State newState = state;
    try {
        byte[] buffer = new byte[Constants.BUFFER_SIZE];
        int readLast = in.read(buffer);
        while (readLast != Constants.NO_BYTES_READ) {
            newState = dataWriter.write(newState, buffer, readLast);
            readLast = in.read(buffer);
        }
        return newState;
    } catch (IOException e) {
        return newState;
    }
}
Example 24
Project: cms-ce-master  File: PdfExtractor.java View source code
@Override
public String extractText(String mimeType, InputStream inputStream, String encoding) throws IOException {
    if (canHandle(mimeType)) {
        PDDocument doc = PDDocument.load(inputStream);
        PDFTextStripper stripper = new PDFTextStripper();
        String text = stripper.getText(doc);
        doc.close();
        return text;
    } else {
        return null;
    }
}
Example 25
Project: ABPlayer-master  File: IOUtils.java View source code
public static byte[] getBytes(InputStream in) {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        byte[] buffer = new byte[8192];
        int len = 0;
        while ((len = in.read(buffer)) != -1) baos.write(buffer, 0, len);
        in.close();
        return baos.toByteArray();
    } catch (IOException e) {
        return null;
    }
}