LocationData
CSDReader::link (DOMElement* element)
throw(CSDReadException)
{
    XMLURL uri(element->getAttribute(X("href")));
    std::string name = Qedo::transcode(uri.getPath());
    std::string::size_type pos = name.find_last_of("/");
    if (pos != std::string::npos)
    {
        name.erase(0, pos + 1);
    }
    
	std::string fileName = path_ + name;
	LocationData data;
	data.uri = Qedo::transcode(element->getAttribute(X("href")));
	data.file = name;

	//
	// get file
	//
    URLInputSource inputSource(uri);
    BinInputStream* inputStream = inputSource.makeStream();
    if (!inputStream)
    {
		NORMAL_ERR2( "CSDReader: cannot find ", name );
        throw CSDReadException();
    }
        
	std::ofstream aFile;
	aFile.open(fileName.c_str(), std::ios::binary|std::ios::app);
	if (!aFile)
	{
		NORMAL_ERR2( "CSDReader: cannot open file ", fileName );
		throw CSDReadException();
	}
    unsigned char* buf = (unsigned char*)malloc(4096);
    unsigned int len = inputStream->readBytes(buf, 4096);
    while (len)
    {
        aFile.write((const char*)buf, len);
        len = inputStream->readBytes(buf, 4096);
    }
    free(buf);
	aFile.close();

    return data;
}
Beispiel #2
0
std::string
CCDReader::link (DOMElement* element)
throw(CCDReadException)
{
    XMLURL uri(element->getAttribute(X("href")));
    std::string name = Qedo::transcode(uri.getPath());
    std::string::size_type pos = name.find_last_of("/");
    if (pos != std::string::npos)
    {
        name.erase(0, pos + 1);
    }

    std::string fileName = path_ + name;
    URLInputSource inputSource(uri);
    BinInputStream* inputStream = inputSource.makeStream();
    if (!inputStream)
    {
        throw CCDReadException();
    }

    std::ofstream aFile;
    aFile.open(fileName.c_str(), std::ios::binary|std::ios::app);
    if (!aFile)
    {
        std::cerr << "Cannot open file " << fileName << std::endl;
        throw CCDReadException();
    }
    unsigned char* buf = (unsigned char*)malloc(4096);
    unsigned int len = inputStream->readBytes(buf, 4096);
    while (len)
    {
        aFile.write((const char*)buf, len);
        len = inputStream->readBytes(buf, 4096);
    }
    free(buf);
    aFile.close();

    return name;
}
static unsigned int binInputStreamReadCallback(void *userData, void *buffer, unsigned int length)
{
  BinInputStream *stream = (BinInputStream*)userData;

  unsigned int result = 0;
  do {
    unsigned int read = stream->readBytes((XMLByte*)buffer + result, length - result);
    if(read == 0) break;

    result += read;
  } while(result < length);

  return result;
}
Beispiel #4
0
void
exercise(BinInputStream& stream)
{
	static float percents[] = { 1.0, 0.5, 0.25, 0.1, 0.15, 0.113, 0.333, 0.0015, 0.0013 };
	int numPercents = sizeof(percents) / sizeof(float);
	
	const unsigned int bufferMax = 4096;
	XMLByte buffer[bufferMax];

	int iteration = 0;
	unsigned int bytesRead = 0;
	do {
		// Calculate a percentage of our maximum buffer size, going through
		// them round-robin
		float percent = percents[iteration % numPercents];
		unsigned int bufCnt = (unsigned int)(bufferMax * percent);
		
		// Check to make sure we didn't go out of bounds
		if (bufCnt <= 0)
			bufCnt = 1;
		if (bufCnt > bufferMax)
			bufCnt = bufferMax;
		
		// Read bytes into our buffer
		bytesRead = stream.readBytes(buffer, bufCnt);
		//XERCES_STD_QUALIFIER cerr << "Read " << bytesRead << " bytes into a " << bufCnt << " byte buffer\n";

		if (bytesRead > 0)
		{
			// Write the data to standard out
			XERCES_STD_QUALIFIER cout.write((char*)buffer, bytesRead);
		}
		
		++iteration;
	} while (bytesRead > 0);
}
Components::Cookie* 
AssemblyFactoryImpl::create_assembly (const char* assembly_loc)
throw (Components::Deployment::InvalidLocation, Components::CreateFailure)
{
	DEBUG_OUT2( "AssemblyFactoryImpl: creating new assembly for ", assembly_loc );

	//
	// exclusive
	//
	QedoLock lock(&mutex_);

	//
	// get path
	//
	XMLURL uri(assembly_loc);
	const XMLCh* p = uri.getPath();
	if(!p)
	{
		NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location: ", assembly_loc );
		throw Components::Deployment::InvalidLocation();
	}
	std::string name = Qedo::transcode(p);
	std::string::size_type pos = name.find_last_of("/");
	if (pos != std::string::npos)
	{
		name.erase(0, pos + 1);
	}

	//
	// make input stream
	//
	URLInputSource inputSource(uri);
	BinInputStream* inputStream;
	try
	{
		inputStream = inputSource.makeStream();
	}
	catch(...)
	{
		NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location: ", assembly_loc );
		throw Components::Deployment::InvalidLocation();
	}
    if (!inputStream)
    {
		NORMAL_ERR2( "AssemblyFactoryImpl: invalid assembly location", assembly_loc );
		throw Components::Deployment::InvalidLocation();
    }

	//
	// create new cookie
	//
	Cookie_impl* new_cookie = new Cookie_impl();
	const char * s =  new_cookie->to_string();
	std::string uuid = s;
	CORBA::string_free(const_cast<char*>(s));

	//
	// store the package
	//
	std::string dir = getPath( packageDirectory_ ) + uuid;
	if( makeDir(dir) )
	{
		NORMAL_ERR3( "AssemblyFactoryImpl: directory ", dir, " can not be created");
		throw Components::CreateFailure();
	}

	std::string package_name = getPath( dir ) + name;
	std::ofstream packageFile(package_name.c_str(), std::ios::binary|std::ios::app);
	if ( ! packageFile)
	{
		NORMAL_ERR2( "AssemblyFactoryImpl: cannot open file ", package_name );
		throw Components::CreateFailure();
	}
    unsigned char* buf = new unsigned char[4096];
    unsigned int len = inputStream->readBytes(buf, 4096);
    while (len)
    {
		packageFile.write((const char*)buf, len);
		len = inputStream->readBytes(buf, 4096);
	}
	delete [] buf;
	packageFile.close();
	delete inputStream;

	//
	// create new assembly
	//
	AssemblyImpl* ass = new AssemblyImpl(package_name, new_cookie, nameService_);
	assemblies_.push_back(ass);

	DEBUG_OUT( "..... done" );

	return new_cookie;
}