use of org.ballerinalang.nativeimpl.io.BallerinaIOException in project ballerina by ballerina-lang.
the class EntityBodyHandler method constructJsonDataSource.
/**
* Construct JsonDataSource from the underneath byte channel which is associated with the entity struct.
*
* @param entityStruct Represent an entity struct
* @return BJSON data source which is kept in memory
*/
public static BJSON constructJsonDataSource(BStruct entityStruct) {
try {
Channel byteChannel = getByteChannel(entityStruct);
if (byteChannel == null) {
return null;
}
BJSON jsonData = new BJSON(byteChannel.getInputStream());
byteChannel.close();
return jsonData;
} catch (IOException e) {
throw new BallerinaIOException("Error occurred while closing connection", e);
}
}
use of org.ballerinalang.nativeimpl.io.BallerinaIOException in project ballerina by ballerina-lang.
the class EntityBodyHandler method constructXmlDataSource.
/**
* Construct XMl data source from the underneath byte channel which is associated with the entity struct.
*
* @param entityStruct Represent an entity struct
* @return BXML data source which is kept in memory
*/
public static BXML constructXmlDataSource(BStruct entityStruct) {
try {
Channel byteChannel = getByteChannel(entityStruct);
if (byteChannel == null) {
throw new BallerinaIOException("Empty xml payload");
}
BXML xmlContent = XMLUtils.parse(byteChannel.getInputStream());
byteChannel.close();
return xmlContent;
} catch (IOException e) {
throw new BallerinaIOException("Error occurred while closing the channel", e);
}
}
use of org.ballerinalang.nativeimpl.io.BallerinaIOException in project ballerina by ballerina-lang.
the class EntityBodyHandler method constructStringDataSource.
/**
* Construct StringDataSource from the underneath byte channel which is associated with the entity struct.
*
* @param entityStruct Represent an entity struct
* @return StringDataSource which represent the entity body which is kept in memory
*/
public static StringDataSource constructStringDataSource(BStruct entityStruct) {
try {
Channel byteChannel = getByteChannel(entityStruct);
if (byteChannel == null) {
throw new BallerinaIOException("Payload is null");
}
String textContent = StringUtils.getStringFromInputStream(byteChannel.getInputStream());
byteChannel.close();
return new StringDataSource(textContent);
} catch (IOException e) {
throw new BallerinaIOException("Error occurred while closing the channel", e);
}
}
Aggregations