use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class FileContainer method createInfoFromLog.
/**
* Set container properties from the passed in ByteArray, which is created
* by logCreateContainerInfo. This information is used to recreate the
* container during recovery load tran.
*
* The following container properties are set:
*
* pageSize
* spareSpace
* minimumRecordSize
* isReusableRecordId
* initialPages
*/
private void createInfoFromLog(ByteArray byteArray) throws StandardException {
if (SanityManager.DEBUG) {
SanityManager.ASSERT(byteArray != null, "setCreateContainerInfoFromLog: ByteArray is null");
SanityManager.ASSERT(byteArray.getLength() == CONTAINER_INFO_SIZE, "setCreateContainerInfoFromLog: ByteArrays.length() != CONTAINER_INFO_SIZE");
}
byte[] array = byteArray.getArray();
// now extract the relevant information from array - basically
// duplicate the code in readHeaderFromArray
ArrayInputStream inStream = new ArrayInputStream(array);
int status = 0;
try {
inStream.setLimit(CONTAINER_INFO_SIZE);
int fid = inStream.readInt();
if (fid != formatIdInteger) {
// RESOLVE: do something about this when we have > 1 container format
throw StandardException.newException(SQLState.DATA_UNKNOWN_CONTAINER_FORMAT, getIdentity(), fid);
}
status = inStream.readInt();
pageSize = inStream.readInt();
spareSpace = inStream.readInt();
minimumRecordSize = inStream.readInt();
initialPages = inStream.readShort();
} catch (IOException ioe) {
throw StandardException.newException(SQLState.DATA_UNEXPECTED_EXCEPTION, ioe);
}
// set reusable record id property
setReusableRecordIdState((status & FILE_REUSABLE_RECORDID) != 0);
// dropped Container
if (SanityManager.DEBUG) {
SanityManager.ASSERT((status & FILE_DROPPED) == 0 && (status & FILE_COMMITTED_DROP) == 0, "cannot load a dropped container");
}
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class ArrayInputStreamTest method testSkipBytesIntMaxValue.
/**
* Test that we don't get an overflow when the argument to skipBytes() is
* Integer.MAX_VALUE (DERBY-3739).
*/
public void testSkipBytesIntMaxValue() throws IOException {
ArrayInputStream ais = new ArrayInputStream(new byte[1000]);
assertEquals(1000, ais.skipBytes(Integer.MAX_VALUE));
assertEquals(1000, ais.getPosition());
ais.setPosition(1);
assertEquals(999, ais.skipBytes(Integer.MAX_VALUE));
assertEquals(1000, ais.getPosition());
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class ArrayInputStreamTest method testSkipBytesNegative.
/**
* Test that skipBytes() returns 0 when the argument is negative
* (DERBY-3739).
*/
public void testSkipBytesNegative() throws IOException {
ArrayInputStream ais = new ArrayInputStream(new byte[1000]);
assertEquals(0, ais.skipBytes(-1));
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project derby by apache.
the class ArrayInputStreamTest method testSkipLongMaxValue.
/**
* Test that we don't get an overflow when the argument to skip() is
* Long.MAX_VALUE (DERBY-3739).
*/
public void testSkipLongMaxValue() throws IOException {
ArrayInputStream ais = new ArrayInputStream(new byte[1000]);
assertEquals(1000, ais.skip(Long.MAX_VALUE));
assertEquals(1000, ais.getPosition());
ais.setPosition(1);
assertEquals(999, ais.skip(Long.MAX_VALUE));
assertEquals(1000, ais.getPosition());
}
use of org.apache.derby.iapi.services.io.ArrayInputStream in project carbon-apimgt by wso2.
the class AbstractAPIManagerTestCase method testGetWsdl.
@Test
public void testGetWsdl() throws APIManagementException, RegistryException, IOException {
Resource resourceMock = Mockito.mock(Resource.class);
AbstractAPIManager abstractAPIManager = new AbstractAPIManagerWrapper(registry);
APIIdentifier identifier = getAPIIdentifier(SAMPLE_API_NAME, API_PROVIDER, SAMPLE_API_VERSION);
String wsdlName = identifier.getProviderName() + "--" + identifier.getApiName() + identifier.getVersion() + ".wsdl";
String wsdlResourcePath = APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + identifier.getProviderName() + RegistryConstants.PATH_SEPARATOR + identifier.getApiName() + RegistryConstants.PATH_SEPARATOR + identifier.getVersion() + RegistryConstants.PATH_SEPARATOR + wsdlName;
Resource resource = new ResourceImpl(wsdlResourcePath, new ResourceDO());
Mockito.when(registry.get(wsdlResourcePath)).thenThrow(RegistryException.class).thenReturn(resource);
Mockito.when(registry.resourceExists(wsdlResourcePath)).thenReturn(true);
try {
abstractAPIManager.getWSDL(identifier);
} catch (APIManagementException e) {
Assert.assertTrue(e.getMessage().contains("Error while getting wsdl file from the registry"));
}
String wsdlContent = "sample wsdl";
resource.setContent(wsdlContent);
InputStream inputStream = new ArrayInputStream();
Mockito.when(resourceMock.getContentStream()).thenReturn(inputStream);
Assert.assertEquals(wsdlContent, IOUtils.toString(abstractAPIManager.getWSDL(identifier).getContent()));
PowerMockito.mockStatic(IOUtils.class);
}
Aggregations