Find the header, remove leading garbage and setup the stream starting from the header.
333685
function PDFDocument_checkHeader() {
      var stream = this.stream;
      stream.reset();
      if (find(stream, '%PDF-', 1024)) {
        // Found the header, trim off any garbage before it.
        stream.moveStart();
        // Reading file format version
        var MAX_VERSION_LENGTH = 12;
        var version = '', ch;
        while ((ch = stream.getByte()) > 0x20) { // SPACE
          if (version.length >= MAX_VERSION_LENGTH) {
            break;
          }
          version += String.fromCharCode(ch);
        }
        if (!this.pdfFormatVersion) {
          // removing "%PDF-"-prefix
          this.pdfFormatVersion = version.substring(5);
        }
        return;
      }
      // May not be a PDF file, continue anyway.
    }
549002
def _ImageHeaderFactory(stream):
    
    from docx.image import SIGNATURES

    def read_32(stream):
        stream.seek(0)
        return stream.read(32)

    header = read_32(stream)
    for cls, offset, signature_bytes in SIGNATURES:
        end = offset + len(signature_bytes)
        found_bytes = header[offset:end]
        if found_bytes == signature_bytes:
            return cls.from_stream(stream)
    raise UnrecognizedImageError
467982
def load_from_stream(self, header):
        """"""
        self._unpack_attrs(header.atts)
        self.name = header.name
        self.lon_lat_domain = header.latlonRect
        self.proj_domain = header.projRect
        self.date_range = header.dateRange
        self.type = header.coverageType

        for sys in header.coordSys:
            self.coord_systems[sys.name] = sys

        for trans in header.coordTransforms:
            self.transforms[trans.name] = trans

        for ax in header.coordAxes:
            self.axes[ax.name] = ax

        for cov in header.grids:
            self.grids[cov.name] = cov
409417
private void processDefaultHeader(ParserContext context) {
        for (String line : context.getFileLines()) {

            if (hasHeaderSeparator(line)) {
                break;
            }
            processHeaderLine(line, context.getDocumentModel());
        }
    }
670950
def set_stream(self, stream):
        

        for handler in self.handlers[:]:
            if isinstance(handler, logging.StreamHandler):
                self.handlers.remove(handler)

        if stream is not None:
            stream_handler = logging.StreamHandler(stream)
            stream_handler.addFilter(_StreamHandlerEchoFilter())
            stream_handler.setFormatter(logging.Formatter('%(message)s'))
            self.addHandler(stream_handler)

        self.stream = stream
1167890
def flush(self):
        
        self.acquire()
        try:
            if self.stream and hasattr(self.stream, "flush"):
                self.stream.flush()
        finally:
            self.release()
307939
def _from_stream(cls, stream, blob, filename=None):
        
        image_header = _ImageHeaderFactory(stream)
        if filename is None:
            filename = 'image.%s' % image_header.default_ext
        return cls(blob, filename, image_header)
972438
def set_header(self,header):
        
        self.header = header
        self.root.insert(0,header.get_node())
923785
protected void CopyHeader()
	{
		seek(0);
        @SuppressWarnings("unused")
		int major = getCard8();
        @SuppressWarnings("unused")
		int minor = getCard8();
        int hdrSize = getCard8();
        @SuppressWarnings("unused")
		int offSize = getCard8();
        nextIndexOffset = hdrSize;
        OutputList.addLast(new RangeItem(buf,0,hdrSize));
	}
986048
private void readHeader(InputStream is) throws IOException
   {
      byte[] header = new byte[20];
      is.read(header);
      m_offset += 20;
      SynchroLogger.log("HEADER", header);   
   }
1168105
def stream_header_legacy(self, f):
        """"""
        stream_struct("L##LL", f, self.version, self.previous_block_hash,
                      self.merkle_root, self.timestamp, self.difficulty)
        f.write(self.nonce[:4])
748757
private void initialize() {
        this.file = null;
        this.header = new TarHeader();

        this.gnuFormat = false;
        this.ustarFormat = true; // REVIEW What we prefer to use...
        this.unixFormat = false;
    }
1041542
public static function startup()
    {

        // setup STDOUT and STDERR defaults
        self::initializeOutputStreams();

        // some init stuff
        self::getTimer()->start();

        self::setSystemConstants();
        self::setIncludePaths();
        self::setIni();
    }
1364405
def draw_header(self, stream, header):
        """"""
        stream.writeln('=' * (len(header) + 4))
        stream.writeln('| ' + header + ' |')
        stream.writeln('=' * (len(header) + 4))
        stream.writeln()
37293
protected void setupPathedInputStream() throws IOException
   {
      InputStream curIn = getBaseResource().openStream();

      for (int i = 0; i < this.segments.length; ++i)
      {
         curIn = getSegmentInputStream(curIn, segments[i]);
      }

      this.in = curIn;
   }
1054729
private void createHeader(RollingSegmentHandle handle) throws StreamSegmentException {
        Preconditions.checkArgument(handle.getHeaderHandle() == null, "handle already has a header.");

        // Create a new Header SegmentChunk.
        String headerName = StreamSegmentNameUtils.getHeaderSegmentName(handle.getSegmentName());
        this.baseStorage.create(headerName);
        val headerHandle = this.baseStorage.openWrite(headerName);

        // Create a new Handle and serialize it, after which update the original handle.
        val newHandle = new RollingSegmentHandle(headerHandle, handle.getRollingPolicy(), handle.chunks());
        serializeHandle(newHandle);
        handle.refresh(newHandle);
    }
597353
void writeHeader(OutputStream stream) throws IOException {
        // try for cached write first
        if (headerBytesValid && payload != null && payload.length >= offset + HEADER_SIZE) {
            stream.write(payload, offset, HEADER_SIZE);
            return;
        }
        // fall back to manual write
        Utils.uint32ToByteStreamLE(version, stream);
        stream.write(prevBlockHash.getReversedBytes());
        stream.write(getMerkleRoot().getReversedBytes());
        Utils.uint32ToByteStreamLE(time, stream);
        Utils.uint32ToByteStreamLE(difficultyTarget, stream);
        Utils.uint32ToByteStreamLE(nonce, stream);
    }