Read the PEM file and save the DER encoded octet
stream and begin marker.

@throws IOException
514452
protected void readFile() throws IOException {

        String  line;
        try(BufferedReader reader=new BufferedReader(
          new InputStreamReader(stream))) {
            while((line=reader.readLine()) != null) {
                if(line.contains(BEGIN_MARKER)) {
                    beginMarker=line.trim();
                    String endMarker=beginMarker.replace("BEGIN", "END");
                    derBytes=readBytes(reader, endMarker);
                    return;
                }
            }
            throw new IOException("Invalid PEM file: no begin marker");
        }
    }
7466
private static byte[] readBytes(BufferedReader reader, String endMarker) throws IOException
    {
        String          line = null;
        StringBuilder   buf = new StringBuilder();

        while ((line = reader.readLine()) != null)
        {
            if (line.contains(endMarker)) {
                return Base64.getDecoder().decode(buf.toString());
            }

            buf.append(line.trim());        
        }

        throw new IOException("Invalid PEM file: No end marker");
    }
673738
public void read(byte[] buffer) throws IOException {
        IO.read(src, buffer);
        ofs += buffer.length;
    }
1161313
public void save() throws IOException {
	if (!file.exists()) file.createFile(true);
	OutputStream out = IOUtil.toBufferedOutputStream(file.getOutputStream());
	Iterator it = sections.keySet().iterator();
	PrintWriter output = new PrintWriter(out);
	try {
	    while (it.hasNext()) {
		String strSection = (String) it.next();
		output.println("[" + strSection + "]");
		Map section = getSectionEL(strSection);
		Iterator iit = section.keySet().iterator();
		while (iit.hasNext()) {
		    String key = (String) iit.next();
		    output.println(key + "=" + section.get(key));
		}
	    }
	}
	finally {
	    IOUtil.flushEL(output);
	    IOUtil.closeEL(output);
	    IOUtil.flushEL(out);
	    IOUtil.closeEL(out);
	}
    }
340022
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream tmp = new DerOutputStream();

        for (int i = 0; i < ids.size(); i++) {
            ids.elementAt(i).encode(tmp);
        }
        out.write(DerValue.tag_Sequence,tmp);
    }
497044
private void readHeader() throws IOException {
		final RandomAccessFile baseFile = mFiles.get(0);

		// Get file sizes
		for (final RandomAccessFile file : mFiles) {
			mFileSizes.add(file.length());
		}

		// Version
		final int version = baseFile.readInt();
		if (version != VERSION) {
			throw new IOException("Bad file version: " + version);
		}

		// Tile Size
		final int tile_size = baseFile.readInt();
		if (tile_size != TILE_SIZE) {
			throw new IOException("Bad tile size: " + tile_size);
		}

		// Read Source List
		final int sourceCount = baseFile.readInt();

		for (int i=0;i<sourceCount;i++) {
			final int sourceIndex = baseFile.readInt();
			final int sourceNameLength = baseFile.readInt();
			final byte[] nameData = new byte[sourceNameLength];
			baseFile.read(nameData, 0, sourceNameLength);

			final String sourceName = new String(nameData);
			mSources.put(new Integer(sourceIndex), sourceName);
		}

		// Read Ranges
		final int num_ranges = baseFile.readInt();
		for (int i=0;i<num_ranges;i++) {
			final GEMFRange rs = new GEMFRange();
			rs.zoom = baseFile.readInt();
			rs.xMin = baseFile.readInt();
			rs.xMax = baseFile.readInt();
			rs.yMin = baseFile.readInt();
			rs.yMax = baseFile.readInt();
			rs.sourceIndex = baseFile.readInt();
			rs.offset = baseFile.readLong();
			mRangeData.add(rs);
		}
	}
575957
public void decode() throws IOException {
        readMetadata();
        try {
            while (true) {
                //switch (state) {
                //case DECODER_SEARCH_FOR_METADATA :
                //    readStreamSync();
                //    break;
                //case DECODER_READ_METADATA :
                //    Metadata metadata = readNextMetadata();
                //    if (metadata == null) break;
                //    break;
                //case DECODER_SEARCH_FOR_FRAME_SYNC :
                findFrameSync();
                //    break;
                //case DECODER_READ_FRAME :
                try {
                    readFrame();
                    frameListeners.processFrame(frame);
                    callPCMProcessors(frame);
                } catch (FrameDecodeException e) {
                    badFrames++;
                }
                //    break;
                //case DECODER_END_OF_STREAM :
                //case DECODER_ABORTED :
                //    return;
                //default :
                //    throw new IOException("Unknown state: " + state);
                //}
            }
        } catch (EOFException e) {
            eof = true;
        }
    }
1008857
public void read() throws IOException {
		long headerSize = header.getHeaderSize();
		int loadModuleSize = getLoadModuleSize();

		try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
			raf.seek(headerSize);
			loadModuleBytes = new byte[loadModuleSize];
			raf.readFully(loadModuleBytes);
		}
	}
1300535
public void encode(DerOutputStream out) throws IOException {

        DerOutputStream tmp = new DerOutputStream();
        hashAlgId.encode(tmp);
        tmp.putOctetString(issuerNameHash);
        tmp.putOctetString(issuerKeyHash);
        certSerialNumber.encode(tmp);
        out.write(DerValue.tag_Sequence, tmp);

        if (debug) {
            HexDumpEncoder encoder = new HexDumpEncoder();
            System.out.println("Encoded certId is " +
                encoder.encode(out.toByteArray()));
        }
    }
465625
private void readFile()
            throws IOException
    {
        BufferedReader reader = null;

        try {
            reader = new BufferedReader( new InputStreamReader( new FileInputStream( file ), PcsUtils.UTF8 ) );

            LOGGER.debug( "Reading credentials file {}", file );

            String line;
            int index = 1;

            while ( ( line = reader.readLine() ) != null ) {
                line = line.trim();

                if ( line.startsWith( "#" ) || line.length() == 0 ) {
                    continue;
                }

                String[] userCredentialsArray = line.split( "=", 2 );

                if ( userCredentialsArray.length != 2 ) {
                    throw new IllegalArgumentException( "Not parsable line #" + index );
                }

                // Key
                final String key = userCredentialsArray[0].trim();
                final Credentials value = Credentials.createFromJson( userCredentialsArray[1].trim() );

                credentialsMap.put( key, value );

                index++;
            }

        } finally {
            PcsUtils.closeQuietly( reader );
        }
    }
1003301
public void read() throws IOException {
		try (RandomAccessFile raf = new RandomAccessFile(file, "r")) {
			// check that offset location is within the file
			throwIf(file.length() < PE_OFFSET_LOCATION);
			/* read pe signature offset at offset location */
			byte[] offsetBytes = loadBytesSafely(PE_OFFSET_LOCATION,
					PE_OFFSET_LOCATION_SIZE, raf);
			// save signature offset
			peOffset = Optional.of((long) bytesToInt(offsetBytes));
			// check if supposed pe signature is within the file
			// a truncated signature has to be taken into account and allowed
			// see d_nonnull.dll
			throwIf(file.length() < peOffset.get() || peOffset.get() < 0);
			/* read PE signature at offset and verify */
			byte[] peSigVal = loadBytesSafely(peOffset.get(), PE_SIG.length,
					raf);
			for (int i = 0; i < PE_SIG.length; i++) {
				throwIf(peSigVal[i] != PE_SIG[i]);
			}
		}
	}
195738
private void initializeContentBuffer() throws IOException {
		if (this.seekEnabled) {
			this.buffer = ByteBuffer.allocate(this.fileSize - HEADER_BYTES);
			final int read = this.stream.read(this.buffer);
			if (read < 0) {
				throw new EOFException();
			}
			this.buffer.rewind();
			this.buffer.limit(read);
			this.bufferPosition = HEADER_BYTES;
		} else {
			this.buffer = ByteBuffer.allocate(BLOCK_SIZE);
			final int read = this.stream.read(this.buffer);
			if (read < 0) {
				throw new EOFException();
			}
			this.buffer.rewind();
			this.buffer.limit(read);
			this.bufferPosition = HEADER_BYTES;
		}
	}
648415
private void encodeThis() throws IOException {
        if (crlNumber == null) {
            this.extensionValue = null;
            return;
        }
        DerOutputStream os = new DerOutputStream();
        os.putInteger(this.crlNumber);
        this.extensionValue = os.toByteArray();
    }
975782
protected void init() throws IOException {
		if (internalIn2 != null)
			return;

		Charset preciseCharset;
		byte bom[] = new byte[BOM_SIZE];
		int n, unread;
		n = internalIn.read(bom, 0, bom.length);

		if ((bom[0] == (byte) 0x00) && (bom[1] == (byte) 0x00) && (bom[2] == (byte) 0xFE) && (bom[3] == (byte) 0xFF)) {
			preciseCharset = Charset.forName("UTF-32BE");
			unread = n - 4;
		} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE) && (bom[2] == (byte) 0x00) && (bom[3] == (byte) 0x00)) {
			preciseCharset = Charset.forName("UTF-32LE");
			unread = n - 4;
		} else if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) {
			preciseCharset = Charset.forName("UTF-8");
			unread = n - 3;
		} else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) {
			preciseCharset = Charset.forName("UTF-16BE");
			unread = n - 2;
		} else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) {
			preciseCharset = Charset.forName("UTF-16LE");
			unread = n - 2;
		} else {
			// Unicode BOM mark not found, unread all bytes
			preciseCharset = charset;
			unread = n;
		}
		if (unread > 0)
			internalIn.unread(bom, (n - unread), unread);

		// Use given encoding
		internalIn2 = preciseCharset == null ? new InputStreamReader(internalIn) : new InputStreamReader(internalIn, preciseCharset);
	}
371347
protected void init() throws IOException {
      if (internalIn2 != null) return;

      String encoding;
      byte bom[] = new byte[BOM_SIZE];
      int n, unread;
      n = internalIn.read(bom, 0, bom.length);

      if ( (bom[0] == (byte)0x00) && (bom[1] == (byte)0x00) &&
                  (bom[2] == (byte)0xFE) && (bom[3] == (byte)0xFF) ) {
         encoding = "UTF-32BE";
         unread = n - 4;
      } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) &&
                  (bom[2] == (byte)0x00) && (bom[3] == (byte)0x00) ) {
         encoding = "UTF-32LE";
         unread = n - 4;
      } else if (  (bom[0] == (byte)0xEF) && (bom[1] == (byte)0xBB) &&
            (bom[2] == (byte)0xBF) ) {
         encoding = "UTF-8";
         unread = n - 3;
      } else if ( (bom[0] == (byte)0xFE) && (bom[1] == (byte)0xFF) ) {
         encoding = "UTF-16BE";
         unread = n - 2;
      } else if ( (bom[0] == (byte)0xFF) && (bom[1] == (byte)0xFE) ) {
         encoding = "UTF-16LE";
         unread = n - 2;
      } else {
         // Unicode BOM mark not found, unread all bytes
         encoding = defaultEnc;
         unread = n;
      }    
      //System.out.println("read=" + n + ", unread=" + unread);

      if (unread > 0) internalIn.unread(bom, (n - unread), unread);

      // Use given encoding
      if (encoding == null) {
         internalIn2 = new InputStreamReader(internalIn);
      } else {
         internalIn2 = new InputStreamReader(internalIn, encoding);
      }
   }
146702
private static byte[] getDecodedPEMObject(BufferedReader reader) throws IOException {
        String line;
        StringBuffer buf = new StringBuffer();
        while ((line = reader.readLine()) != null) {
            if (line.indexOf("--END") != -1) { // found end
                return Base64.decode(buf.toString().getBytes());
            } else {
                buf.append(line);
            }
        }
        throw new EOFException("Missing PEM end footer");
    }
168637
public void encode(DerOutputStream out) throws IOException {
        DerOutputStream seq = new DerOutputStream();

        for (int i = 0, n = size(); i < n; i++) {
            get(i).encode(seq);
        }
        out.write(DerValue.tag_Sequence, seq);
    }