Hendré
Hendré

Reputation: 300

Java method available in Eclipse, but not in Android

I use the readAllBytes() method from the CipherInputStream class in a library in Eclipse, however, when I use the library in Android, the method is not available. I have my source compatibility set to JAVA_1_8 for both the Android and Eclipse projects.

Why is the readAllBytes() method not available in Android?

Upvotes: 0

Views: 71

Answers (2)

Maksim Novikov
Maksim Novikov

Reputation: 834

I believe this is the function you looking for:

    /**
         * Copies all available data from in to out without closing any stream.
         *
         * @return number of bytes copied
         */
        private static final int BUFFER_SIZE = 8192;
        public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
            int byteCount = 0;
            byte[] buffer = new byte[BUFFER_SIZE];
            while (true) {
                int read = in.read(buffer);
                if (read == -1) {
                    break;
                }
                out.write(buffer, 0, read);
                byteCount += read;
            }
            return byteCount;
        }

Upvotes: 1

rzwitserloot
rzwitserloot

Reputation: 102923

readAllBytes was introduced with java10+, android isn't that far into it yet. Source compatibility is about which java language features are available. You can configure which JVM to use separately; install a JDK8 and point eclipse at that. Then getAllBytes should disappear.

Upvotes: 3

Related Questions