void ScorePageBase::readStream(istream& testfile, int verboseQ) {
   int binaryQ = 0;  // to test if reading a binary or PMX data file.

   if (&testfile == &cin) {
      // presume that standard input is PMX data, and not binary data.
      binaryQ = 0;
   } else {
      // The last 4 bytes of a binary SCORE file are 00 3c 1c c6 which equals
      // the float value -9999.0.
      testfile.seekg(-4, ios::end);
      unsigned char databytes[4] = {0xff};
      testfile.read((char*)databytes, 4);
      if (databytes[0] == 0x00 && databytes[1] == 0x3c &&
            databytes[2] == 0x1c && databytes[3] == 0xc6) {
         binaryQ = 1;
      } else {
         binaryQ = 0;
      }
      testfile.seekg(0, ios::beg);
   }

   if (binaryQ) {
      readBinary(testfile, verboseQ);
   } else {
      readPmx(testfile, verboseQ);
   }
}
Exemple #2
0
static size_t getStreamSize(istream& stream) {
    auto startPosition = stream.tellg();
    stream.seekg(0, ios_base::end);
    auto fileSize = static_cast<size_t>(stream.tellg());
    stream.seekg(startPosition);
    return fileSize;
}
Exemple #3
0
bool Point3Dot::load(istream &in){
  coords.resize(3);
  int start = in.tellg();
  for(int i = 0; i < 3; i++){
    in >> coords[i];
    if(in.fail()){
      in.clear();
      in.seekg(start+1); //????????? Why that one
      return false;
    }
  }
  in >> theta;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  in >> phi;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  int typeInt;
  in >> typeInt;
  type = (Type)typeInt;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  return true;
}
Exemple #4
0
/* Reads a whole file/stream: somewhat inelegant */
string read_whole_stream(istream& in) {
	in.seekg(0, ios::end);
	string buf(in.tellg(), '$');
	in.seekg(0, ios::beg);
	in.read(&buf[0], buf.size());
	return buf;
}
void
readsection(HeaderInfo &rwh, uint32 build, uint32 level, istream &rw)
{
	for(uint32 i = 0; i < level; i++)
		cout << "  ";
	string name = getChunkName(rwh.type);
	cout << name << " (" << hex << rwh.length << " bytes @ 0x" <<
	  hex << rw.tellg()-(streampos)12 << "/0x" << hex << rw.tellg() <<
	  ") - [0x" << hex << rwh.type << "] " << rwh.build << endl;

	streampos end = rw.tellg() + (streampos)rwh.length;

	while(rw.tellg() < end){
		HeaderInfo newrwh;
		newrwh.read(rw);

		if(newrwh.build == build){
			readsection(newrwh, build, level+1, rw);

			/* Native Data PLG has the wrong length */
			if(rwh.type == 0x510)
				rw.seekg(end, ios::beg);
		}else{
			streampos sp = rw.tellg()+(streampos)rwh.length;
			sp -= 12;
			rw.seekg(sp, ios::beg);
			break;
		}
	}
}
Exemple #6
0
string parser::preprocess_input(istream &stream)
{
    streampos start = stream.tellg();
    stream.seekg(0, ios::end);
    streampos end = stream.tellg();
    size_t file_size = end - start;
    stream.seekg(start, ios::beg);
    char bom_test[3];
    static const char * BOM = "\xEF\xBB\xBF";
    stream.read(bom_test, 3u);
    if (strncmp(bom_test, BOM, 3u) == 0) {
        // Matched BOM, keep stream position to prevent its reading
        file_size -= 3u;
    }
    else {
        // Seek stream back
        stream.seekg(start, ios::beg);
    }
    char * buffer = new char[file_size + 1];
    stream.read(buffer, file_size);
    buffer[file_size] = '\0';
    string s0(buffer);
    delete[] buffer;
    string s1 = fix_corrupted_data(s0);
    return s1;
}
Exemple #7
0
size_t get_fsize(istream& is)
{
    size_t fsize = is.tellg();
    is.seekg(0, std::ios::end);
    fsize = size_t(is.tellg()) - fsize;
    is.seekg(0, std::ios::beg);
    return fsize;
}
Exemple #8
0
    BinaryReader(istream &is): buffer(nullptr), size(0), pos(0) {
        is.seekg (0, ios::end);
        size = is.tellg();
        is.seekg (0, ios::beg);

        buffer = new char[size];
        is.read(buffer, size);
        is.seekg(0, ios::beg);
    }
Exemple #9
0
font font::open_font(istream& thefile,int ptsize,long index) {
    thefile.seekg(0,ios::end);
    int filesize=thefile.tellg();
    thefile.seekg(0,ios::beg);
    auto_ptr<vector<char> > filecont(new vector<char>(filesize));
    thefile.read(&(*filecont)[0],filesize);
    SDL_RWops* wop=SDL_RWFromConstMem(&(*filecont)[0],filesize);
    TTF_Font* thefont = TTF_OpenFontIndexRW(wop,true,ptsize,index);
    return font().build(thefont,filecont);
}
Exemple #10
0
FrFILETYPE FrFileType(istream &in)
{
   char buf[BUFFER_SIZE] ;
   long pos = in.tellg() ;
   in.seekg(0) ;
   (void)in.read(buf,sizeof(buf)) ;
   FrFILETYPE type = check_type(buf,in.gcount()) ;
   in.seekg(pos) ;
   return type ;
}
Exemple #11
0
std::streampos Data::_getStreamSize(istream &stream) {
  auto current_pos = stream.tellg();

  //Retrieve length
  stream.seekg(0, stream.end);
  auto endpos = stream.tellg();

  //Restore old position
  stream.seekg(current_pos, stream.beg);

  return endpos - current_pos;
}
Exemple #12
0
DecisionTreePtr DecisionTree::readC5(istream& in, AttributeSpec* spec)
{
    int tag;
    in.read((char*)&tag, sizeof(int));
    if (memcmp((char *)&tag, "id=", 3) == 0)
    {
        in.seekg (0, ios::beg);
        return readC5Text(in, spec);
    }
    in.seekg(0, ios::beg);
    return readC5Bin(in, spec);
}
void JackPlugin::StreamIn (istream &s) 
{
	char Test;
	int Version, NumInputs, NumOutputs;

	s.seekg (2, ios::cur );  //skip to next line
	Test = s.peek();         //peek first char
	s.seekg (-2, ios::cur ); //jump back to prior line
	
	if ( (Test >= '0') && (Test <= '9') )
	{
		s >> Version;
	}
void SplitterPlugin::StreamIn (istream &s) 
{
	char Test;
	int Version, Channels;

	s.seekg (2, ios::cur );//skip to next line
	Test = s.peek();//peek first char
	s.seekg (-2, ios::cur );//jump back to prior line 
	
	if ( (Test >= '0') && (Test <= '9') )
	{
		s >> Version;
	}
Exemple #15
0
XingStreamBase::XingStreamBase(int nIndex, NoteColl& notes, istream& in) : MpegStreamBase(nIndex, notes, in), m_nFrameCount(-1), m_nByteCount(-1), m_nQuality(-1)
{
    fill(&m_toc[0], &m_toc[100], 0);
    in.seekg(m_pos);

    const int XING_LABEL_SIZE (4);
    const int BFR_SIZE (MpegFrame::MPEG_FRAME_HDR_SIZE + 32 + XING_LABEL_SIZE); // MPEG header + side info + "Xing" size //ttt2 not sure if space for CRC16 should be added; then not sure if frame size should be increased by 2 when CRC is found
    char bfr [BFR_SIZE];

    int nSideInfoSize (m_firstFrame.getSideInfoSize());

    int nBfrSize (MpegFrame::MPEG_FRAME_HDR_SIZE + nSideInfoSize + XING_LABEL_SIZE);

    MP3_CHECK_T (nBfrSize <= m_firstFrame.getSize(), m_pos, "Not a Xing stream. This kind of MPEG audio doesn't support Xing.", NotXingStream()); // !!! some kinds of MPEG audio (e.g. "MPEG-1 Layer I, 44100Hz 32000bps" or "MPEG-2 Layer III, 22050Hz 8000bps") have very short frames, which can't accomodate a Xing header

    streamsize nRead (read(in, bfr, nBfrSize));
    STRM_ASSERT (nBfrSize == nRead); // this was supposed to be a valid frame to begin with (otherwise the base class would have thrown) and nBfrSize is no bigger than the frame

    char* pLabel (bfr + MpegFrame::MPEG_FRAME_HDR_SIZE + nSideInfoSize);
    MP3_CHECK_T (0 == strncmp("Xing", pLabel, XING_LABEL_SIZE) || 0 == strncmp("Info", pLabel, XING_LABEL_SIZE), m_pos, "Not a Xing stream. Header not found.", NotXingStream());

    MP3_CHECK_T (4 == read(in, bfr, 4) && 0 == bfr[0] && 0 == bfr[1] && 0 == bfr[2], m_pos, "Not a Xing stream. Header not found.", NotXingStream());
    m_cFlags = bfr[3];
    MP3_CHECK_T ((m_cFlags & 0x0f) == m_cFlags, m_pos, "Not a Xing stream. Invalid flags.", NotXingStream());
    if (0x01 == (m_cFlags & 0x01))
    { // has frames
        MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
        m_nFrameCount = get32BitBigEndian(bfr);
    }

    if (0x02 == (m_cFlags & 0x02))
    { // has bytes
        MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
        m_nByteCount = get32BitBigEndian(bfr);
    }

    if (0x04 == (m_cFlags & 0x04))
    { // has TOC
        MP3_CHECK_T (100 == read(in, m_toc, 100), m_pos, "Not a Xing stream. File too short.", NotXingStream());
    }

    if (0x08 == (m_cFlags & 0x08))
    { // has quality
        MP3_CHECK_T (4 == read(in, bfr, 4), m_pos, "Not a Xing stream. File too short.", NotXingStream());
        m_nQuality = get32BitBigEndian(bfr);
    }

    streampos posEnd (m_pos);
    posEnd += m_firstFrame.getSize();
    in.seekg(posEnd); //ttt2 2010.12.07 - A header claiming to have TOC but lacking one isn't detected. 1) Should check that values in TOC are ascending. 2) Should check that it actually fits: a 104 bytes-long 32kbps frame cannot hold a 100 bytes TOC along with the header and other things.
}
Exemple #16
0
ossimErrorCode ossimRpfFrame::populateImageSection(istream& in)
{
   ossimErrorCode result = ossimErrorCodes::OSSIM_OK;
   if(theImageDescriptionSubheader) delete theImageDescriptionSubheader;
   theImageDescriptionSubheader = 0;
   if(theHeader&&in)
   {
      // get the subheader information.
      theImageDescriptionSubheader = theHeader->getNewImageDescriptionSubheader(in);

      
      // need to do something with the table before going to the display.
      if(theImageDescriptionSubheader &&(!theImageDescriptionSubheader->isSubframeMaskTableOffsetNull()))
      {
         if(theMaskSubheader) delete theMaskSubheader;
         // need to get the mask subheader
         theMaskSubheader = new ossimRpfMaskSubheader;

         // seek to the start of the subheader
         in.seekg(theImageDescriptionSubheader->getEndOffset() +
                  theImageDescriptionSubheader->getSubframeMaskTableOffset(), ios::beg);

         // get the information
         result = theMaskSubheader->parseStream(in, theHeader->getByteOrder());
      }

      if(theImageDisplayParameterSubheader) delete theImageDisplayParameterSubheader;
      // Get the display parameter header
      theImageDisplayParameterSubheader = theHeader->getNewImageDisplayParameterSubheader(in);
   }
   return result;
}
Exemple #17
0
bool DSA1Intro::read(istream& strm) {
    header_size = 20;
    file_size   = filesize(strm);
    count       = read16(strm);
    // TODO: Was bedeutet der Rest des Headers?
    strm.seekg(0x20);
    while(strm.tellg() < file_size) {
	DSA1Intro_Entry* entry = new DSA1Intro_Entry;
	if (!entry->read(strm)) {
	    entry->name    = "DUMMY";
	    entry->size    = 0;
	    entry->volname = "DUMMY";
	    entry->offset  = 0;
	    entries.push_back(entry);
	    //delete entry;
	} else {
	    // Nach Duplikaten suchen und diese entfernen
	    /*for (u32 j=0; j<entries.size(); j++) {
		if (entry->name == entries[j]->name) {
		    delete entry;
		    entry = 0;
		    break;
		}
		}*/
	    if (entry == 0) continue;
	    else entries.push_back(entry);
	}
    }
    //assert(count == entries.size());
    return true;
 }
Exemple #18
0
/**
 * Author: [email protected]
 * Date: 24/10/13
 * Time: 18:36
 */
Lexer::Lexer(istream &inputstream)
{
	if(inputstream)
	{		
		inputstream.seekg (0, inputstream.end);
		length = inputstream.tellg();
		inputstream.seekg (0, inputstream.beg);
		bytes = new char [length]; 
		//std::cout << "Reading " << length << " characters... "  << endl;
		inputstream.read (bytes,length);	
	}else{
		throw  KevoreeException("Lexer inputstream is null");
	}
	finish_token = new Token(END_OF_FILE,"");
	index =0;
}
Exemple #19
0
void CL_TimeOfDay::FromStream (istream& s)
{
    CL_String rep;
    char c;
    long count = 0;
    char fill_char = s.fill ();
    
    while (s.get (c) && c == fill_char);
    if (!s.good() || s.eof()) {
        _numSecs = 0;
        return;
    }
    do {
        if (isalnum (c) || c == ':') {
            rep.Append (c);
            count++;
        }
        else
            break;
    } while (s.get (c));

    long n = ParseAndConvert (rep);
    if (n > 0) {
        if (!s.eof())
            s.putback (c);
        _numSecs = n;
    }
    else {
        s.seekg (s.tellg() - count, istream::cur);
        _numSecs = 0;
    }
}
Exemple #20
0
vector< vector< double > > loadMatrix(istream &file) {
    vector< vector< double > > toReturn;
    int pos;
    string s;
    int matrix_width = 0;
    while(getline(file,s))
    {
        //Ignores files with a #
        size_t found = s.find("#");
        if(found!=string::npos)
            continue;
        vector< double > vd;
        stringstream ss(s);
        double d;
        while(!ss.fail()) {
            ss >> d;
            if(!ss.fail()) {
                vd.push_back(d);
            }
        }
        if(matrix_width==0)
            matrix_width = vd.size();
        if(vd.size() == matrix_width) {
            toReturn.push_back(vd);
        } else {
            // Return before the string that has been read
            file.seekg(pos);
            break;
        }
        pos = file.tellg();
    }
    return toReturn;
}
Exemple #21
0
 // Skips one matrix in an input stream.
 void skip_matrix_double(istream& input_stream)
 {
   int m, n;
   input_stream.read(reinterpret_cast<char*>(&m), sizeof(int));
   input_stream.read(reinterpret_cast<char*>(&n), sizeof(int));
   input_stream.seekg(m * n * sizeof(double), istream::cur);
 }
Exemple #22
0
CppSeqFile::Reader::Reader(istream& in, long start, long length) :
  _in(in), _dis(in)
{
  _start = start;
  if (length >= 0)
  {
    _end = start + length;
  }
  else
  {
    long p = in.tellg();
    in.seekg(0, ios_base::end);
    _end = in.tellg();
    in.seekg(p, ios_base::beg);
  }
  _init();
}
int IOBuffer::DRead(istream & stream, int recref)
// read specified record
		{
	stream.seekg(recref, ios::beg);
	if(stream.tellg() != recref)
		return -1;
	return Read(stream);
}
void GalaxyFDSClient::prepareRequestHeaders(const string& uri,
    const string& httpMethod, const string& mediaType, istream& is,
    const FDSObjectMetadata& metadata, HTTPRequest& request) {
  shared_ptr<LinkedListMultimap> pHeaders(new LinkedListMultimap());

  // metadata
  for (map<string, string>::const_iterator iter = metadata.metadata().begin();
      iter != metadata.metadata().end(); ++iter) {
    (*pHeaders)[iter->first].push_back(iter->second);
  }

  // date
  string date = DateTimeFormatter::format(DateTime(),
      GalaxyFDSClient::DATE_FORMAT);
  (*pHeaders)[Constants::DATE].push_back(date);

  // content type
  if (!mediaType.empty()) {
    (*pHeaders)[Constants::CONTENT_TYPE].push_back(mediaType);
  }

  // content length
  if (!is.seekg(0, is.end).fail()) {
    request.setContentLength(is.tellg());
    is.seekg(0, is.beg);
  } else {
    request.setChunkedTransferEncoding(true);
  }

  // authentication information
  string relativeUri = uri.substr(uri.find_first_of('/',
      uri.find_first_of(':') + 3));
  string signature = Signer::SignToBase64(httpMethod, relativeUri, *pHeaders,
      _secretKey, kHmacSha1);
  string authStr = "Galaxy-V2 " + _accessKey + ":" + signature;
  (*pHeaders)[Constants::AUTHORIZATION].push_back(authStr);

  for (LinkedListMultimap::iterator iter = pHeaders->begin();
      iter != pHeaders->end(); ++iter) {
    for (list<string>::iterator iterList = iter->second.begin();
        iterList != iter->second.end(); ++iterList) {
      request.add(iter->first, *iterList);
    }
  }
}
void
JSeekg
	(
	istream&	stream,
	long		position
	)
{
	stream.seekg((streamoff) position);
}
Exemple #26
0
void load_rec(ephemrec &r, istream &in, int idx)
{
	in.seekg(idx*sizeof(r));
	if(!in.read((char *)&r, sizeof(r)))
	{
		std::cerr << "Error while reading binary record. Aborting\n";
		abort();
	}
}
void
JSeekg
	(
	istream&	stream,
	streampos	position
	)
{
	stream.seekg(position);
}
Exemple #28
0
bool Point2Do::load(istream &in){
  coords.resize(3);
  int start = in.tellg();
  for(int i = 0; i < 2; i++){
    in >> coords[i];
    if(in.fail()){
      in.clear();
      in.seekg(start+1); //????????? Why that one
      return false;
    }
  }
  in >> theta;
  if(in.fail()){
    in.clear();
    in.seekg(start+1); //????????? Why that one
    return false;
  }
  return true;
}
void
JSeekg
	(
	istream&			stream,
	streamoff			offset,
	JIOStreamSeekDir	direction
	)
{
	stream.seekg(offset, direction);
}
void
JSeekg
	(
	istream&			stream,
	long				offset,
	JIOStreamSeekDir	direction
	)
{
	stream.seekg((streamoff) offset, direction);
}