encode InputStream onto Output Stream

@param is
@param estimate
@return
@throws IOException
964869
public void encode(InputStream is, OutputStream os) throws IOException {
    	// StringBuilder sb = new StringBuilder((int)(estimate*1.255)); // try to get the right size of StringBuilder from start.. slightly more than 1.25 times 
    	int prev=0;
    	int read, idx=0, line=0;
    	boolean go;
    	do {
    		read = is.read();
    		if(go = read>=0) {
    			if(line>=splitLinesAt) {
	    			os.write('\n');
	    			line = 0;
	    		}
	    		switch(++idx) { // 1 based reading, slightly faster ++
	    			case 1: // ptr is the first 6 bits of read
	    				os.write(codeset[read>>2]);
	    				prev = read;
	    				break;
	    			case 2: // ptr is the last 2 bits of prev followed by the first 4 bits of read
	    				os.write(codeset[((prev & 0x03)<<4) | (read>>4)]);
    					prev = read;
	    				break;
	    			default: //(3+) 
	    					// Char 1 is last 4 bits of prev plus the first 2 bits of read
	    				    // Char 2 is the last 6 bits of read
	    				os.write(codeset[(((prev & 0xF)<<2) | (read>>6))]);
	    				if(line==splitLinesAt) { // deal with line splitting for two characters
	    					os.write('\n');
	    					line=0;
	    				}
	    				os.write(codeset[(read & 0x3F)]);
	    				++line;
	    				idx = 0;
	    				prev = 0;
	    		}
	    		++line;
    		} else { // deal with any remaining bits from Prev, then pad
    			switch(idx) {
    				case 1: // just the last 2 bits of prev
	    				os.write(codeset[(prev & 0x03)<<4]);
    					if(endEquals)os.write(DOUBLE_EQ);
    					break;
    				case 2: // just the last 4 bits of prev
	    				os.write(codeset[(prev & 0xF)<<2]);
	    				if(endEquals)os.write('=');
	    				break;
    			}
    			idx = 0;
    		}
    		
    	} while(go);
    }
627143
public void initFromBackup(InputStream is) throws IOException {
    int count = 0;
    try (GzipCompressorInputStream gzIn = new GzipCompressorInputStream(is);
         JournalEntryStreamReader reader = new JournalEntryStreamReader(gzIn)) {
      List<Master> masters = mRegistry.getServers();
      JournalEntry entry;
      Map<String, Master> mastersByName = Maps.uniqueIndex(masters, Master::getName);
      while ((entry = reader.readEntry()) != null) {
        String masterName = JournalEntryAssociation.getMasterForEntry(entry);
        Master master = mastersByName.get(masterName);
        try {
          master.processJournalEntry(entry);
        } catch (Throwable t) {
          JournalUtils.handleJournalReplayFailure(
              LOG, t, "Failed to process journal entry %s when init from backup", entry);
        }
        try (JournalContext jc = master.createJournalContext()) {
          jc.append(entry);
          count++;
        }
      }
    }
    LOG.info("Restored {} entries from backup", count);
  }
501596
public void encode(OutputStream out)
    throws CertificateException, IOException {
        if (rawCertInfo == null) {
            DerOutputStream tmp = new DerOutputStream();
            emit(tmp);
            rawCertInfo = tmp.toByteArray();
        }
        out.write(rawCertInfo.clone());
    }
1356330
public static void save(Object o, OutputStream stream) {
        try {
            ObjectOutputStream outStream = 
                (stream instanceof ObjectOutputStream)
                    ? (ObjectOutputStream)stream
                    : new ObjectOutputStream(stream);
            outStream.writeObject(o);
        } catch (IOException ioe) {
            throw new IOError(ioe);
        }
    }
26372
public static void compress(InputStream is, OutputStream os) throws Exception {
		GZIPOutputStream gos = new GZIPOutputStream(os);
		int count;
		byte data[] = new byte[BUFFER];
		while ((count = is.read(data, 0, BUFFER)) != -1) {
			gos.write(data, 0, count);
		}
		gos.finish();
		gos.flush();
		gos.close();
	}
292129
public void handleInputStream(final InputStream is) throws IOException
        {
        LOG.trace("Handling input stream.");
        final OutputStream os = new FileOutputStream(this.m_file);
        try
            {
            final long bytesWritten = org.littleshoot.util.IoUtils.copy(is, os, 
                this.m_writeListener);
            LOG.trace("Wrote "+bytesWritten+" to file: "+this.m_file);
            }
        finally
            {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
            }
        }
6864
private void streamContent(HttpServletResponse response, InputStream is) throws IOException {

        OutputStream os = response.getOutputStream();
        try {
            byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
            int bytes;
            while ((bytes = is.read(buffer)) >= 0) {
                os.write(buffer, 0, bytes);
            }
        } finally {
            os.close();
        }
    }
391646
public static void copy(InputStream is, Resource out, boolean closeIS) throws IOException {
	OutputStream os = null;
	try {
	    os = toBufferedOutputStream(out.getOutputStream());
	}
	catch (IOException ioe) {
	    IOUtil.closeEL(os);
	    throw ioe;
	}
	copy(is, os, closeIS, true);
    }
221729
public void encode(String string, OutputStream out) throws IOException {
  		encode(new ByteArrayInputStream(string.getBytes()),out);
	}
315892
public void encode(ByteBuffer aBuffer, OutputStream aStream)
        throws IOException {
        byte [] buf = getBytes(aBuffer);
        encode(buf, aStream);
    }
192122
public void encode(OutputStream out) throws IOException {
        DerOutputStream tmp = new DerOutputStream();
        if (extensionValue == null) {
            extensionId = PKIXExtensions.SubjectKey_Id;
            critical = false;
            encodeThis();
        }
        super.encode(tmp);
        out.write(tmp.toByteArray());
    }
196654
public static int write(InputStream is, OutputStream os, boolean closeSink) {
        return copy(is, os, closeSink);
    }
708310
static void encode(Environment environment, LocalFunctionRegistry registry, Class returnType, Object result, OutputStream output) throws IOException {
        if (ClassUtils.isJavaLangType(returnType)) {
            if (result instanceof Byte) {
                output.write((Byte) result);
            } else if (result instanceof Boolean) {
                output.write(((Boolean) result) ? 1 : 0);
            } else if (result instanceof byte[]) {
                output.write((byte[]) result);
            } else {
                byte[] bytes = environment
                    .convert(result.toString(), byte[].class)
                    .orElseThrow(() -> new InvocationException("Unable to convert result [" + result + "] for output stream"));
                output.write(bytes);
            }
        }
116452
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream tmp = new DerOutputStream();
        policyIdentifier.encode(tmp);
        if (!policyQualifiers.isEmpty()) {
            DerOutputStream tmp2 = new DerOutputStream();
            for (PolicyQualifierInfo pq : policyQualifiers) {
                tmp2.write(pq.getEncoded());
            }
            tmp.write(DerValue.tag_Sequence, tmp2);
        }
        out.write(DerValue.tag_Sequence, tmp);
    }
36558
public static void skip(InputStream is) throws IOException {
        while (is.available() > 0) {
            is.skip(Long.MAX_VALUE);
        }
        is.close();
    }
703076
static public void copyStream(InputStream is, OutputStream os) throws IOException {
		copyStream(is, os, DEFAULT_TRANSFER_BUFFER_SIZE);
	}
547055
public static void compressString(InputStream inputStream, OutputStream outputStream) throws IOException {
        try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
            fillExportStreamCompress(inputStream, byteArrayOutputStream);
            // to do -> make it in chunks
            String result = getStringFromEncode(byteArrayOutputStream.toByteArray());
            try (PrintWriter printWriter = new PrintWriter(outputStream)) {
                printWriter.write(result);
            }
        }
    }