Read base64 data up to an end marker and decode them.

@param in the input reader to read from.
@param endMarker the end marker.
@return the data read.
@throws IOException on error.
437782
protected byte[] readBytes(BufferedReader in, String endMarker) throws IOException
    {
        String line;
        StringBuilder buf = new StringBuilder();

        while ((line = in.readLine()) != null) {
            if (line.contains(endMarker)) {
                break;
            }
            buf.append(line.trim());
        }

        return this.base64.decode(buf.toString());
    }
481456
public int readMarker(SequenceFile.Reader reader) throws IOException {
    if (valueBytes == null) {
      valueBytes = reader.createValueBytes();
    }
    rawKey.reset();
    rawValue.reset();

    // valueBytes need not be reset since nextRaw call does it (and it is a private method)
    int status = reader.nextRaw(rawKey, valueBytes);

    // if we reach EOF, return -1
    if (status == -1) {
      return -1;
    }

    // Check if the marker key is valid and return the count
    if (isMarkerValid()) {
      valueBytes.writeUncompressedBytes(rawValue);
      rawValue.flush();
      // rawValue.getData() may return a larger byte array but Ints.fromByteArray will only read the first four bytes
      return Ints.fromByteArray(rawValue.getData());
    }

    // EOF not reached and marker is not valid, then thrown an IOException since we can't make progress
    throw new IOException(String.format("Invalid key for num entries appended found %s, expected : %s",
                                        new String(rawKey.getData()), TxConstants.TransactionLog.NUM_ENTRIES_APPENDED));
  }
1194767
public <T> T parse(byte[] in, JsonReaderI<T> mapper) throws ParseException {
		this.base = mapper.base;
		this.in = in;
		this.len = in.length;
		return parse(mapper);
	}
346700
public static Document parseBase64(String base64Data, Element instruction)
            throws Exception {
        byte[] imageData = Base64.decodeBase64(base64Data);
        ByteArrayInputStream bais = new ByteArrayInputStream(imageData);
        StringWriter swLogger = new StringWriter();
        PrintWriter pwLogger = new PrintWriter(swLogger);
        return parse(bais, instruction, pwLogger);
    }
34023
public void read(NutDataInputStream in, long startcode) throws IOException {
    this.startcode = startcode;
    forwardPtr = in.readVarLong();
    if (forwardPtr > 4096) {
      long expected = in.getCRC();
      checksum = in.readInt();
      if (checksum != expected) {
        // TODO This code path has never been tested.
        throw new IOException(
            String.format("invalid header checksum %X want %X", expected, checksum));
      }
    }

    in.resetCRC();
    end = in.offset() + forwardPtr - 4; // 4 bytes for footer CRC
  }
1267355
private byte[] read(InputStream in) throws IOException {
		ByteArrayOutputStream out = new ByteArrayOutputStream(READ_FILE_BASE_SIZE);
		byte[] buffer = new byte[READ_BUFFER_SIZE];
		int count = in.read(buffer);
		while (count != -1) {
			if (count != 0) {
				out.write(buffer, 0, count);
			}
			count = in.read(buffer);
		}
		in.close();
		return out.toByteArray();
	}
465191
public static byte[] decode(InputStream in) {
        try {
            return IOUtils.toByteArray(decodeToStream(in));
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    }
520095
public static BlockMetadataHeader readHeader(DataInputStream in,
                                Checksum checksumImpl) throws IOException {
    return readHeader(in.readShort(), in, checksumImpl);
  }
490696
private static FieldInfo readFieldInfo(BigEndianBinaryReader in) throws IOException {
        byte type = in.expectByte();
        if (type == BinaryType.STOP) {
            return null;
        }
        return new FieldInfo(in.expectShort(), type);
    }
328857
public long readRawLittleEndian64() throws IOException
    {
        // final byte[] buffer = this.buffer;
        // int offset = this.offset;

        final byte[] bs = new byte[8];
        buffer.get(bs);

        // final byte b1 = buffer[offset++];
        // final byte b2 = buffer[offset++];
        // final byte b3 = buffer[offset++];
        // final byte b4 = buffer[offset++];
        // final byte b5 = buffer[offset++];
        // final byte b6 = buffer[offset++];
        // final byte b7 = buffer[offset++];
        // final byte b8 = buffer[offset++];
        //
        // this.offset = offset;

        return (((long) bs[0] & 0xff)) |
                (((long) bs[1] & 0xff) << 8) |
                (((long) bs[2] & 0xff) << 16) |
                (((long) bs[3] & 0xff) << 24) |
                (((long) bs[4] & 0xff) << 32) |
                (((long) bs[5] & 0xff) << 40) |
                (((long) bs[6] & 0xff) << 48) |
                (((long) bs[7] & 0xff) << 56);
    }
1120134
public final static int readXML(final StringBuilder out, final String in, final int start, final boolean safeMode)
    {
        int pos;
        final boolean isCloseTag;
        try
        {
            if (in.charAt(start + 1) == '/')
            {
                isCloseTag = true;
                pos = start + 2;
            }
            else if (in.charAt(start + 1) == '!')
            {
                out.append("<!");
                return start + 1;
            }
            else
            {
                isCloseTag = false;
                pos = start + 1;
            }
            if (safeMode)
            {
                final StringBuilder temp = new StringBuilder();
                pos = readXMLUntil(temp, in, pos, ' ', '/', '>');
                if (pos == -1)
                {
                    return -1;
                }
                final String tag = temp.toString().trim().toLowerCase();
                if (HTML.isUnsafeHtmlElement(tag))
                {
                    out.append("&lt;");
                }
                else
                {
                    out.append("<");
                }
                if (isCloseTag)
                {
                    out.append('/');
                }
                out.append(temp);
            }
            else
            {
                out.append('<');
                if (isCloseTag)
                {
                    out.append('/');
                }
                pos = readXMLUntil(out, in, pos, ' ', '/', '>');
            }
            if (pos == -1)
            {
                return -1;
            }
            pos = readXMLUntil(out, in, pos, '/', '>');
            if (in.charAt(pos) == '/')
            {
                out.append(" /");
                pos = readXMLUntil(out, in, pos + 1, '>');
                if (pos == -1)
                {
                    return -1;
                }
            }
            if (in.charAt(pos) == '>')
            {
                out.append('>');
                return pos;
            }
        }
        catch (final StringIndexOutOfBoundsException e)
        {
            return -1;
        }
        return -1;
    }
533277
public final static int readUntil(final StringBuilder out, final String in, final int start, final char... end)
    {
        int pos = start;
        while (pos < in.length())
        {
            final char ch = in.charAt(pos);
            if (ch == '\\' && pos + 1 < in.length())
            {
                pos = escape(out, in.charAt(pos + 1), pos);
            }
            else
            {
                boolean endReached = false;
                for (int n = 0; n < end.length; n++)
                {
                    if (ch == end[n])
                    {
                        endReached = true;
                        break;
                    }
                }
                if (endReached)
                {
                    break;
                }
                out.append(ch);
            }
            pos++;
        }

        return (pos == in.length()) ? -1 : pos;
    }
390785
public static String read(InputStream in) throws IOException {
        InputStreamReader isReader = new InputStreamReader(in, "UTF-8");
        BufferedReader reader = new BufferedReader(isReader);
        StringBuffer out = new StringBuffer();
        char[] c = new char[4096];
        for (int n; (n = reader.read(c)) != -1;) {
            out.append(new String(c, 0, n));
        }
        reader.close();

        return out.toString();
    }
974739
private void parseDER(DerInputStream in) throws IOException {
        //
        // X.500 names are a "SEQUENCE OF" RDNs, which means zero or
        // more and order matters.  We scan them in order, which
        // conventionally is big-endian.
        //
        DerValue[] nameseq = null;
        byte[] derBytes = in.toByteArray();

        try {
            nameseq = in.getSequence(5);
        } catch (IOException ioe) {
            if (derBytes == null) {
                nameseq = null;
            } else {
                DerValue derVal = new DerValue(DerValue.tag_Sequence,
                                           derBytes);
                derBytes = derVal.toByteArray();
                nameseq = new DerInputStream(derBytes).getSequence(5);
            }
        }

        if (nameseq == null) {
            names = new RDN[0];
        } else {
            names = new RDN[nameseq.length];
            for (int i = 0; i < nameseq.length; i++) {
                names[i] = new RDN(nameseq[i]);
            }
        }
    }
1262157
protected static <T> T parse(String in, JsonReaderI<T> mapper) {
		try {
			JSONParser p = new JSONParser(DEFAULT_PERMISSIVE_MODE);
			return p.parse(in, mapper);
		} catch (Exception e) {
			return null;
		}
	}
954142
public static void decodeFileToFile(String infile, String outfile) throws IOException {
		byte[] decoded = Base64.decodeFromFile(infile);
		java.io.OutputStream out = null;
		try{
			out = new java.io.BufferedOutputStream(new FileOutputStream(outfile));
			out.write(decoded);
		} catch (IOException e) {
			throw e; // Catch and release to execute finally{}
		} finally {
			try {
				if (out != null) {
					out.close();
				}
			} catch (Exception ex) {
			}
		}
	}
1161754
public Buffer readFrom(InputStream in) throws IOException {
    readFrom(in, Long.MAX_VALUE, true);
    return this;
  }