Search in sources :

Example 11 with ArrayInputStream

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");
    }
}
Also used : ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) IOException(java.io.IOException)

Example 12 with ArrayInputStream

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());
}
Also used : ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 13 with ArrayInputStream

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));
}
Also used : ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 14 with ArrayInputStream

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());
}
Also used : ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream)

Example 15 with ArrayInputStream

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);
}
Also used : ResourceImpl(org.wso2.carbon.registry.core.ResourceImpl) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ResourceDO(org.wso2.carbon.registry.core.jdbc.dataobjects.ResourceDO) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) InputStream(java.io.InputStream) Resource(org.wso2.carbon.registry.core.Resource) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) ArrayInputStream(org.apache.derby.iapi.services.io.ArrayInputStream) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ArrayInputStream (org.apache.derby.iapi.services.io.ArrayInputStream)28 ByteArrayInputStream (java.io.ByteArrayInputStream)16 IOException (java.io.IOException)11 StandardException (org.apache.derby.shared.common.error.StandardException)4 PageKey (org.apache.derby.iapi.store.raw.PageKey)3 LogRecord (org.apache.derby.impl.store.raw.log.LogRecord)3 EOFException (java.io.EOFException)2 InputStream (java.io.InputStream)2 ErrorObjectInput (org.apache.derby.iapi.services.io.ErrorObjectInput)2 FormatIdInputStream (org.apache.derby.iapi.services.io.FormatIdInputStream)2 StreamStorable (org.apache.derby.iapi.services.io.StreamStorable)2 DataValueDescriptor (org.apache.derby.iapi.types.DataValueDescriptor)2 LogCounter (org.apache.derby.impl.store.raw.log.LogCounter)2 StreamLogScan (org.apache.derby.impl.store.raw.log.StreamLogScan)2 CRC32 (java.util.zip.CRC32)1 Compensation (org.apache.derby.iapi.store.raw.Compensation)1 Loggable (org.apache.derby.iapi.store.raw.Loggable)1 RePreparable (org.apache.derby.iapi.store.raw.RePreparable)1 Undoable (org.apache.derby.iapi.store.raw.Undoable)1 LogInstant (org.apache.derby.iapi.store.raw.log.LogInstant)1