/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache POI" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache POI", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
*
*
unfinishedString
.
*
* @param record The data from the continuation record.
*/
private void processEntireContinuation( final byte[] record )
{
// create artificial data to create a UnicodeString
int dataLengthInBytes = record.length - LittleEndianConsts.BYTE_SIZE;
byte[] unicodeStringData = new byte[record.length + LittleEndianConsts.SHORT_SIZE];
LittleEndian.putShort( unicodeStringData, (byte) 0, (short) calculateCharCount( dataLengthInBytes ) );
arraycopy( record, 0, unicodeStringData, LittleEndianConsts.SHORT_SIZE, record.length );
UnicodeString ucs = new UnicodeString( UnicodeString.sid, (short) unicodeStringData.length, unicodeStringData );
unfinishedString = unfinishedString + ucs.getString();
setContinuationExpectedChars( getContinuationExpectedChars() - calculateCharCount( dataLengthInBytes ) );
}
private boolean stringSpansContinuation( int continuationSizeInBytes )
{
return calculateByteCount( getContinuationExpectedChars() ) > continuationSizeInBytes;
}
/**
* @return the number of characters we expect in the first
* sub-record in a subsequent continuation record
*/
int getContinuationExpectedChars()
{
return continuationExpectedChars;
}
private void setContinuationExpectedChars( final int count )
{
continuationExpectedChars = count;
}
private int calculateByteCount( final int character_count )
{
return character_count * ( wideChar ? LittleEndianConsts.SHORT_SIZE : LittleEndianConsts.BYTE_SIZE );
}
/**
* Copies an array from the specified source array, beginning at the
* specified position, to the specified position of the destination array.
* A subsequence of array components are copied from the source
* array referenced by src
to the destination array
* referenced by dst
. The number of components copied is
* equal to the length
argument. The components at
* positions srcOffset
through
* srcOffset+length-1
in the source array are copied into
* positions dstOffset
through
* dstOffset+length-1
, respectively, of the destination
* array.
*
* If the src
and dst
arguments refer to the
* same array object, then the copying is performed as if the
* components at positions srcOffset
through
* srcOffset+length-1
were first copied to a temporary
* array with length
components and then the contents of
* the temporary array were copied into positions
* dstOffset
through dstOffset+length-1
of the
* destination array.
*
* If dst
is null
, then a
* NullPointerException
is thrown.
*
* If src
is null
, then a
* NullPointerException
is thrown and the destination
* array is not modified.
*
* Otherwise, if any of the following is true, an
* ArrayStoreException
is thrown and the destination is
* not modified:
*
src
argument refers to an object that is not an
* array.
* dst
argument refers to an object that is not an
* array.
* src
argument and dst
argument refer to
* arrays whose component types are different primitive types.
* src
argument refers to an array with a primitive
* component type and the dst
argument refers to an array
* with a reference component type.
* src
argument refers to an array with a reference
* component type and the dst
argument refers to an array
* with a primitive component type.
*
* Otherwise, if any of the following is true, an
* IndexOutOfBoundsException
is
* thrown and the destination is not modified:
*
srcOffset
argument is negative.
* dstOffset
argument is negative.
* length
argument is negative.
* srcOffset+length
is greater than
* src.length
, the length of the source array.
* dstOffset+length
is greater than
* dst.length
, the length of the destination array.
*
* Otherwise, if any actual component of the source array from
* position srcOffset
through
* srcOffset+length-1
cannot be converted to the component
* type of the destination array by assignment conversion, an
* ArrayStoreException
is thrown. In this case, let
* k be the smallest nonnegative integer less than
* length such that src[srcOffset+
k]
* cannot be converted to the component type of the destination
* array; when the exception is thrown, source array components from
* positions srcOffset
through
* srcOffset+
k-1
* will already have been copied to destination array positions
* dstOffset
through
* dstOffset+
k-1
and no other
* positions of the destination array will have been modified.
* (Because of the restrictions already itemized, this
* paragraph effectively applies only to the situation where both
* arrays have component types that are reference types.)
*
* @param src the source array.
* @param src_position start position in the source array.
* @param dst the destination array.
* @param dst_position pos start position in the destination data.
* @param length the number of array elements to be copied.
* @exception IndexOutOfBoundsException if copying would cause
* access of data outside array bounds.
* @exception ArrayStoreException if an element in the src
* array could not be stored into the dest
array
* because of a type mismatch.
* @exception NullPointerException if either src
or
* dst
is null
.
*/
private void arraycopy( byte[] src, int src_position,
byte[] dst, int dst_position,
int length )
{
System.arraycopy( src, src_position, dst, dst_position, length );
}
/**
* @return the unfinished string
*/
String getUnfinishedString()
{
return unfinishedString;
}
/**
* @return true if current string uses wide characters
*/
boolean isWideChar()
{
return wideChar;
}
}