public byte[] readFully(InputStream st) {
        ByteArrayOutputStream stream = new ByteArrayOutputStream();

        int read;
        try {
            while (readLen.getAndDecrement() > 0 && (read = st.read()) != -1) {
                stream.write(read);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }


        return stream.toByteArray();
    }
Create an ApnsServerStub that uses any free port for gateway and feedback.

@return the server stub. Use getEffectiveGatewayPort() and getEffectiveFeedbackPort() to ask for ports.
src/test/java/com/notnoop/apns/utils/ApnsServerStub.java