Input: { [CODESPLIT] public int write ( byte [ ] buf , int size ) { if ( mOpenStream == null || ! ( mOpenStream instanceof OutputStream ) ) return - 1 ; try { OutputStream stream = ( OutputStream ) mOpenStream ; stream . write ( buf , 0 , size ) ; return size ; } catch ( IOException e ) { log . error ( "Got error writing to file: {}; {}" , mOpenStream , e ) ; return - 1 ; } }


Input: Get the set of keys currently in this { [CODESPLIT] public java . util . Collection < String > getKeys ( ) { int numKeys = getNumKeys ( ) ; java . util . List < String > retval = new java . util . ArrayList < String > ( numKeys ) ; for ( int i = 0 ; i < getNumKeys ( ) ; i ++ ) { String key = getKey ( i ) ; if ( key != null && key . length ( ) > 0 ) retval . add ( key ) ; } return retval ; }


Input:
Get the value for the given key .

 [CODESPLIT] public String getValue ( String key , KeyValueBag . Flags flag ) { return VideoJNI . KeyValueBag_getValue ( swigCPtr , this , key , flag . swigValue ( ) ) ; }


Input:
Sets the value for the given key to value . This overrides
 any prior setting for key or adds key to the meta - data
 if appropriate .

 [CODESPLIT] public int setValue ( String key , String value ) { return VideoJNI . KeyValueBag_setValue__SWIG_0 ( swigCPtr , this , key , value ) ; }


Input: Create a new KeyValueBag bag of properties with<br > no values set . [CODESPLIT] public static KeyValueBag make ( ) { long cPtr = VideoJNI . KeyValueBag_make ( ) ; return ( cPtr == 0 ) ? null : new KeyValueBag ( cPtr , false ) ; }


Input:
Sets the value for the given key to value . This overrides
 any prior setting for key or adds key to the meta - data
 if appropriate .

 [CODESPLIT] public int setValue ( String key , String value , KeyValueBag . Flags flag ) { return VideoJNI . KeyValueBag_setValue__SWIG_1 ( swigCPtr , this , key , value , flag . swigValue ( ) ) ; }


Input:
Open this Coder using the given bag of Codec - specific options .

 [CODESPLIT] public void open ( KeyValueBag inputOptions , KeyValueBag unsetOptions ) { VideoJNI . Coder_open ( swigCPtr , this , KeyValueBag . getCPtr ( inputOptions ) , inputOptions , KeyValueBag . getCPtr ( unsetOptions ) , unsetOptions ) ; }


Input:
The Codec this StreamCoder will use .

 [CODESPLIT] public Codec getCodec ( ) { long cPtr = VideoJNI . Coder_getCodec ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Codec ( cPtr , false ) ; }


Input:
Get the time base this stream will ENCODE in or the time base we
 detect while DECODING .

 [CODESPLIT] public Rational getTimeBase ( ) { long cPtr = VideoJNI . Coder_getTimeBase ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Rational ( cPtr , false ) ; }


Input:
Set the time base we ll use to ENCODE with . A no - op when DECODING .

 As a convenience we forward this call to the Stream#setTimeBase ()
 method .

 [CODESPLIT] public void setTimeBase ( Rational newTimeBase ) { VideoJNI . Coder_setTimeBase ( swigCPtr , this , Rational . getCPtr ( newTimeBase ) , newTimeBase ) ; }


Input: Set a flag to true or false . [CODESPLIT] public void setFlag ( Coder . Flag flag , boolean value ) { VideoJNI . Coder_setFlag ( swigCPtr , this , flag . swigValue ( ) , value ) ; }


Input: Set a flag2 to true or false . [CODESPLIT] public void setFlag2 ( Coder . Flag2 flag , boolean value ) { VideoJNI . Coder_setFlag2 ( swigCPtr , this , flag . swigValue ( ) , value ) ; }


Input: Get the decoder that can decode the information in this Demuxer stream . [CODESPLIT] public Decoder getDecoder ( ) { long cPtr = VideoJNI . DemuxerStream_getDecoder ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Decoder ( cPtr , false ) ; }


Input: Get the Demuxer this DemuxerStream belongs to . [CODESPLIT] public Demuxer getDemuxer ( ) { long cPtr = VideoJNI . DemuxerStream_getDemuxer ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Demuxer ( cPtr , false ) ; }


Input: Return a collection of all output formats installed on this system . [CODESPLIT] public static java . util . Collection < MuxerFormat > getFormats ( ) { java . util . Collection < MuxerFormat > retval = new java . util . HashSet < MuxerFormat > ( ) ; int count = getNumFormats ( ) ; for ( int i = 0 ; i < count ; ++ i ) { MuxerFormat fmt = getFormat ( i ) ; if ( fmt != null ) retval . add ( fmt ) ; } return retval ; }


Input:
Return the sink format in the list of registered sink formats
 which best matches the provided parameters or return NULL if
 there is no match .

 [CODESPLIT] public static MuxerFormat guessFormat ( String shortName , String filename , String mimeType ) { long cPtr = VideoJNI . MuxerFormat_guessFormat ( shortName , filename , mimeType ) ; return ( cPtr == 0 ) ? null : new MuxerFormat ( cPtr , false ) ; }


Input:
Get the Codec . ID for the n th codec supported by this container .

 [CODESPLIT] protected Codec . ID getSupportedCodecId ( int n ) { return Codec . ID . swigToEnum ( VideoJNI . MuxerFormat_getSupportedCodecId ( swigCPtr , this , n ) ) ; }


Input:
Return an object for the input format at the given index .

 [CODESPLIT] public static MuxerFormat getFormat ( int index ) { long cPtr = VideoJNI . MuxerFormat_getFormat ( index ) ; return ( cPtr == 0 ) ? null : new MuxerFormat ( cPtr , false ) ; }


Input: Creates a new FilterGraph . [CODESPLIT] public static FilterGraph make ( ) { long cPtr = VideoJNI . FilterGraph_make ( ) ; return ( cPtr == 0 ) ? null : new FilterGraph ( cPtr , false ) ; }


Input: Add a filter with the given name to the graph . <br > [CODESPLIT] public Filter addFilter ( FilterType type , String name ) { long cPtr = VideoJNI . FilterGraph_addFilter ( swigCPtr , this , FilterType . getCPtr ( type ) , type , name ) ; return ( cPtr == 0 ) ? null : new Filter ( cPtr , false ) ; }


Input: Add a FilterAudioSource . <br > [CODESPLIT] public FilterAudioSource addAudioSource ( String name , int sampleRate , AudioChannel . Layout channelLayout , AudioFormat . Type format , Rational timeBase ) { long cPtr = VideoJNI . FilterGraph_addAudioSource ( swigCPtr , this , name , sampleRate , channelLayout . swigValue ( ) , format . swigValue ( ) , Rational . getCPtr ( timeBase ) , timeBase ) ; return ( cPtr == 0 ) ? null : new FilterAudioSource ( cPtr , false ) ; }


Input: Add a FilterPictureSource . <br > [CODESPLIT] public FilterPictureSource addPictureSource ( String name , int width , int height , PixelFormat . Type format , Rational timeBase , Rational pixelAspectRatio ) { long cPtr = VideoJNI . FilterGraph_addPictureSource ( swigCPtr , this , name , width , height , format . swigValue ( ) , Rational . getCPtr ( timeBase ) , timeBase , Rational . getCPtr ( pixelAspectRatio ) , pixelAspectRatio ) ; return ( cPtr == 0 ) ? null : new FilterPictureSource ( cPtr , false ) ; }


Input: Add a FilterAudioSink . <br > [CODESPLIT] public FilterAudioSink addAudioSink ( String name , int sampleRate , AudioChannel . Layout channelLayout , AudioFormat . Type format ) { long cPtr = VideoJNI . FilterGraph_addAudioSink ( swigCPtr , this , name , sampleRate , channelLayout . swigValue ( ) , format . swigValue ( ) ) ; return ( cPtr == 0 ) ? null : new FilterAudioSink ( cPtr , false ) ; }


Input: Add a FilterPictureSink . <br > [CODESPLIT] public FilterPictureSink addPictureSink ( String name , PixelFormat . Type format ) { long cPtr = VideoJNI . FilterGraph_addPictureSink ( swigCPtr , this , name , format . swigValue ( ) ) ; return ( cPtr == 0 ) ? null : new FilterPictureSink ( cPtr , false ) ; }


Input:
Queue a command for one or more filter instances .

 [CODESPLIT] public void queueCommand ( String target , String command , String arguments , int flags , double ts ) { VideoJNI . FilterGraph_queueCommand ( swigCPtr , this , target , command , arguments , flags , ts ) ; }


Input:
Create a new IndexEntry with the specified
 values .

 [CODESPLIT] public static IndexEntry make ( long position , long timeStamp , int flags , int size , int minDistance ) { long cPtr = VideoJNI . IndexEntry_make ( position , timeStamp , flags , size , minDistance ) ; return ( cPtr == 0 ) ? null : new IndexEntry ( cPtr , false ) ; }


Input:
Create a filter given the name .

 [CODESPLIT] public static BitStreamFilter make ( String filtername ) { long cPtr = VideoJNI . BitStreamFilter_make__SWIG_0 ( filtername ) ; return ( cPtr == 0 ) ? null : new BitStreamFilter ( cPtr , false ) ; }


Input:
Create a filter given the type .

 [CODESPLIT] public static BitStreamFilter make ( BitStreamFilterType type ) { long cPtr = VideoJNI . BitStreamFilter_make__SWIG_1 ( BitStreamFilterType . getCPtr ( type ) , type ) ; return ( cPtr == 0 ) ? null : new BitStreamFilter ( cPtr , false ) ; }


Input: Get the type of this filter . [CODESPLIT] public BitStreamFilterType getType ( ) { long cPtr = VideoJNI . BitStreamFilter_getType ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new BitStreamFilterType ( cPtr , false ) ; }


Input:
Filter the input buffer into the output buffer .

 [CODESPLIT] public int filter ( Buffer output , int outputOffset , Buffer input , int inputOffset , int inputSize , Coder coder , String args , boolean isKey ) { return VideoJNI . BitStreamFilter_filter__SWIG_0 ( swigCPtr , this , Buffer . getCPtr ( output ) , output , outputOffset , Buffer . getCPtr ( input ) , input , inputOffset , inputSize , Coder . getCPtr ( coder ) , coder , args , isKey ) ; }


Input:
Filters a packet in place ( i . e . the prior contents will be replaced
 with the filtered data ) .

 This method assumes packet . getCoder () is the coder that is being used
 for outputting the packet to a stream . If this is not the case use
 the other filter mechanism and construct packets yourself .

 [CODESPLIT] public void filter ( MediaPacket packet , String args ) { VideoJNI . BitStreamFilter_filter__SWIG_1 ( swigCPtr , this , MediaPacket . getCPtr ( packet ) , packet , args ) ; }


Input: Absolute bulk put method . <p > This method transfers bytes into this buffer from the given source array . If there are more bytes to be copied from the array than there is space remaining at the specified destination offset then no bytes are transferred and a java . nio . BufferOverflowException is thrown . < / p > <p > This method is equivalent to calling { @link #getByteBuffer ( int int ) } yourself and copying the bytes over but is more efficient in the { @link JNIMemoryManager . MemoryModel#NATIVE_BUFFERS } memory model . < / p > [CODESPLIT] public void put ( byte [ ] src , int srcPos , int destPos , int length ) { java . util . concurrent . atomic . AtomicReference < JNIReference > ref = new java . util . concurrent . atomic . AtomicReference < JNIReference > ( ) ; java . nio . ByteBuffer buffer = this . getByteBuffer ( 0 , this . getBufferSize ( ) , ref ) ; try { if ( buffer == null ) return ; buffer . clear ( ) ; validateArgs ( src , src . length , srcPos , buffer . limit ( ) , destPos , length ) ; buffer . position ( destPos ) ; buffer . put ( src , srcPos , length ) ; return ; } finally { if ( ref . get ( ) != null ) ref . get ( ) . delete ( ) ; } }


Input: Returns up to length bytes starting at offset in the underlying buffer we re managing . [CODESPLIT] public java . nio . ByteBuffer getByteBuffer ( int offset , int length ) { return getByteBuffer ( offset , length , null ) ; }


Input: Returns up to length bytes starting at offset in the underlying buffer we re managing and also passed back a { @link JNIReference } that can optionally be used by the caller to free the underlying native memory . [CODESPLIT] public java . nio . ByteBuffer getByteBuffer ( int offset , int length , java . util . concurrent . atomic . AtomicReference < JNIReference > referenceReturn ) { java . nio . ByteBuffer retval = this . java_getByteBuffer ( offset , length ) ; if ( retval != null ) { // increment the ref count of this class to reflect the // byte buffer java . util . concurrent . atomic . AtomicLong refCount = this . getJavaRefCount ( ) ; refCount . incrementAndGet ( ) ; // and use the byte buffer as the reference to track JNIReference ref = JNIReference . createNonFerryReference ( this , retval , swigCPtr , refCount ) ; if ( referenceReturn != null ) referenceReturn . set ( ref ) ; // and tell Java this byte buffer is in native order retval . order ( java . nio . ByteOrder . nativeOrder ( ) ) ; retval . position ( 0 ) ; retval . mark ( ) ; retval . limit ( this . getBufferSize ( ) ) ; } return retval ; }


Input:
Allocate a new buffer of at least bufferSize .

 [CODESPLIT] public static Buffer make ( RefCounted requestor , int bufferSize ) { long cPtr = FerryJNI . Buffer_make__SWIG_0 ( RefCounted . getCPtr ( requestor ) , requestor , bufferSize ) ; return ( cPtr == 0 ) ? null : new Buffer ( cPtr , false ) ; }


Input:
Allocate a new buffer of at least bufferSize .

 [CODESPLIT] public static Buffer make ( RefCounted requestor , Buffer . Type type , int numElements , boolean zero ) { long cPtr = FerryJNI . Buffer_make__SWIG_1 ( RefCounted . getCPtr ( requestor ) , requestor , type . swigValue ( ) , numElements , zero ) ; return ( cPtr == 0 ) ? null : new Buffer ( cPtr , false ) ; }


Input:
Allocate a new Buffer and copy the data in buffer into
 the new Buffer object .

 [CODESPLIT] public static Buffer make ( RefCounted requestor , byte [ ] buffer , int offset , int length ) { long cPtr = FerryJNI . Buffer_make__SWIG_2 ( RefCounted . getCPtr ( requestor ) , requestor , buffer , offset , length ) ; return ( cPtr == 0 ) ? null : new Buffer ( cPtr , false ) ; }


Input:
Create a new Buffer object that uses the direct byte buffer
 passed in by reference ( i . e . it directly uses the bytes in
 the direct byte buffer ) .

 [CODESPLIT] public static Buffer make ( RefCounted requestor , java . nio . ByteBuffer directByteBuffer , int offset , int length ) { long cPtr = FerryJNI . Buffer_make__SWIG_3 ( RefCounted . getCPtr ( requestor ) , requestor , directByteBuffer , offset , length ) ; return ( cPtr == 0 ) ? null : new Buffer ( cPtr , false ) ; }


Input: Get a connection to the speaker if available . [CODESPLIT] public static AudioFrame make ( final AudioFormat audioFormat ) { try { return new AudioFrame ( audioFormat ) ; } catch ( LineUnavailableException e ) { log . error ( "Could not get audio data line: {}" , e . getMessage ( ) ) ; return null ; } }


Input: Play the given bytes ( in { [CODESPLIT] public void play ( ByteBuffer rawAudio ) { byte [ ] data = rawAudio . array ( ) ; mLine . write ( data , rawAudio . position ( ) , rawAudio . limit ( ) ) ; }


Input: Re - sample a picture . [CODESPLIT] protected static MediaPicture resample ( MediaPicture input , MediaPictureResampler resampler ) { // create new picture object MediaPicture output = MediaPicture . make ( resampler . getOutputWidth ( ) , resampler . getOutputHeight ( ) , resampler . getOutputFormat ( ) ) ; return resample ( output , input , resampler ) ; }


Input: Test that the passed image is valid and conforms to the converters specifications . [CODESPLIT] protected void validateImage ( BufferedImage image ) { // if the image is NULL, throw up if ( image == null ) throw new IllegalArgumentException ( "The passed image is NULL." ) ; // if image is not the correct type, throw up if ( image . getType ( ) != getImageType ( ) ) throw new IllegalArgumentException ( "The passed image is of type #" + image . getType ( ) + " but is required to be of BufferedImage type #" + getImageType ( ) + "." ) ; }


Input: Test that the passed picture is valid and conforms to the converters specifications . [CODESPLIT] protected void validatePicture ( MediaPicture picture ) { // if the picture is NULL, throw up if ( picture == null ) throw new IllegalArgumentException ( "The picture is NULL." ) ; // if the picture is not complete, throw up if ( ! picture . isComplete ( ) ) throw new IllegalArgumentException ( "The picture is not complete." ) ; // if the picture is an invalid type throw up PixelFormat . Type type = picture . getFormat ( ) ; if ( ( type != getPictureType ( ) ) && ( willResample ( ) && type != mToImageResampler . getOutputFormat ( ) ) ) throw new IllegalArgumentException ( "Picture is of type: " + type + ", but must be " + getPictureType ( ) + ( willResample ( ) ? " or " + mToImageResampler . getOutputFormat ( ) : "" ) + "." ) ; }


Input: { [CODESPLIT] @ Override public boolean isInterrupted ( ) { final Thread thread = mThreads . get ( ) . mThread ; final Interruptable handler = getGlobalInterruptHandler ( ) ; boolean retval = false ; if ( handler != null ) { retval = handler . preInterruptCheck ( ) ; if ( ! retval ) return retval ; } retval = thread . isInterrupted ( ) ; if ( handler != null ) { retval = handler . postInterruptCheck ( retval ) ; } return retval ; }


Input: { [CODESPLIT] @ Override public void interrupt ( ) { final Thread thread = mThreads . get ( ) . mThread ; log . trace ( "interrupt (thread {})" , thread ) ; thread . interrupt ( ) ; return ; }


Input: Get the FilterGraph this FilterLink belongs to . [CODESPLIT] public FilterGraph getFilterGraph ( ) { long cPtr = VideoJNI . FilterLink_getFilterGraph ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new FilterGraph ( cPtr , false ) ; }


Input:
Define the time base used by the PTS of the frames / samples
 which will pass through this link .
 During the configuration stage each filter is supposed to
 change only the output timebase while the timebase of the
 input link is assumed to be an unchangeable property .

 [CODESPLIT] public Rational getTimeBase ( ) { long cPtr = VideoJNI . FilterLink_getTimeBase ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Rational ( cPtr , false ) ; }


Input: Insert a filter into this link between the current input and output . <br > [CODESPLIT] public void insertFilter ( Filter filter , int srcPadIndex , int dstPadIndex ) { VideoJNI . FilterLink_insertFilter ( swigCPtr , this , Filter . getCPtr ( filter ) , filter , srcPadIndex , dstPadIndex ) ; }


Input:
Get the time base that time stamps of this object are represented in .

 [CODESPLIT] public Rational getTimeBase ( ) { long cPtr = VideoJNI . MediaRaw_getTimeBase ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Rational ( cPtr , false ) ; }


Input: Get any meta - data associated with this media item [CODESPLIT] public KeyValueBag getMetaData ( ) { long cPtr = VideoJNI . MediaRaw_getMetaData ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new KeyValueBag ( cPtr , false ) ; }


Input:
Sets the timebase on this object .

 Note : This will NOT automatically rescale the timestamp set -- so if you change
 the timebase you almost definitely want to change the timestamp as well . [CODESPLIT] public void setTimeBase ( Rational timeBase ) { VideoJNI . MediaRaw_setTimeBase ( swigCPtr , this , Rational . getCPtr ( timeBase ) , timeBase ) ; }


Input: Register a new factory for IURLProtocolHandlers for a given protocol . <p > FFMPEG is very picky ; protocols must be only alpha characters ( no numbers ) . < / p > [CODESPLIT] public IURLProtocolHandlerFactory registerFactory ( String protocol , IURLProtocolHandlerFactory factory ) { if ( protocol == null ) throw new IllegalArgumentException ( "protocol required" ) ; IURLProtocolHandlerFactory oldFactory ; if ( factory == null ) oldFactory = mProtocols . remove ( protocol ) ; else oldFactory = mProtocols . put ( protocol , factory ) ; log . trace ( "Registering factory for URLProtocol: {}" , protocol ) ; if ( oldFactory == null ) { // we previously didn't have something registered for this factory // so tell FFMPEG we're now the protocol manager for this protocol. log . trace ( "Letting FFMPEG know about an additional protocol: {}" , protocol ) ; FfmpegIO . registerProtocolHandler ( protocol , this ) ; } return oldFactory ; }


Input: / * Get a IURLProtocolHandler for this url . <p > IMPORTANT : This function is called from native code and so the name and signature cannot change without changing the native code . < / p > <p > This function is eventually invoked whenever someone tries to call url_open ( yourprotocol : ... flags ) from FFMPEG native code . It returns a protocol handler which will then have open ( ... ) called on it . < / p > @param url The URL we want to handle . @param flags Any flags that the url_open () function will want to pass . [CODESPLIT] public IURLProtocolHandler getHandler ( String url , int flags ) { IURLProtocolHandler result = null ; log . trace ( "looking for protocol handler for: {}" , url ) ; if ( url == null || url . length ( ) == 0 ) throw new IllegalArgumentException ( "expected valid URL" ) ; int colonIndex = url . indexOf ( ":" ) ; String protocol = null ; if ( colonIndex > 0 ) { protocol = url . substring ( 0 , colonIndex ) ; } else { protocol = DEFAULT_PROTOCOL ; } IURLProtocolHandlerFactory factory = mProtocols . get ( protocol ) ; if ( factory != null ) { result = factory . getHandler ( protocol , url , flags ) ; } else { log . error ( "asked to get handler for unsupported protocol: {}" , protocol ) ; } return result ; }


Input: Get the resource portion of a url . For example for the URL <pre > http : // www . humble . io / video < / pre > The protocol string is <code > http< / code > and the resource string is <code > www . humble . io / video< / code > [CODESPLIT] public static String getResourceFromURL ( String url ) { String retval = url ; if ( url != null && url . length ( ) > 0 ) { int colonIndex ; colonIndex = url . indexOf ( "://" ) ; if ( colonIndex > 0 ) retval = url . substring ( colonIndex + 3 ) ; else { colonIndex = url . indexOf ( ":" ) ; if ( colonIndex > 1 ) // handle windows drive letters. { // remove the URL prefix retval = url . substring ( colonIndex + 1 ) ; } } } return retval ; }


Input: Get the protocol portion of a url . For example for the URL <pre > http : // www . humble . io / video < / pre > The protocol string is <code > http< / code > and the resource string is <code > // www . humble . io / video< / code > [CODESPLIT] public static String getProtocolFromURL ( String url ) { String retval = null ; if ( url != null && url . length ( ) > 0 ) { int colonIndex = url . indexOf ( ":" ) ; if ( colonIndex > 0 ) { // remove the URL suffix retval = url . substring ( 0 , colonIndex ) ; } } return retval ; }


Input: Get the CPU architecture based on the passed in javaCPUArch specifier . [CODESPLIT] public static CPUArch getCPUArch ( String javaCPU ) { final CPUArch javaArch ; final String javaCPUArch = javaCPU != null ? javaCPU . toLowerCase ( ) : "" ; // first parse the java arch if ( javaCPUArch . startsWith ( "x86_64" ) || javaCPUArch . startsWith ( "amd64" ) || javaCPUArch . startsWith ( "ia64" ) ) { javaArch = CPUArch . X86_64 ; } else if ( javaCPUArch . startsWith ( "ppc64" ) || javaCPUArch . startsWith ( "powerpc64" ) ) { javaArch = CPUArch . PPC64 ; } else if ( javaCPUArch . startsWith ( "ppc" ) || javaCPUArch . startsWith ( "powerpc" ) ) { javaArch = CPUArch . PPC ; } else if ( javaCPUArch . contains ( "86" ) ) { javaArch = CPUArch . X86 ; } else { javaArch = CPUArch . UNKNOWN ; } return javaArch ; }


Input: Return a CPUArch from parsing a GNU autoconf triple . [CODESPLIT] public static CPUArch getCPUArchFromGNUString ( String gnuString ) { final String nativeCpu = gnuString . toLowerCase ( ) ; final CPUArch nativeArch ; // then the native arch if ( nativeCpu . startsWith ( "x86_64" ) || nativeCpu . startsWith ( "amd64" ) || nativeCpu . startsWith ( "ia64" ) ) nativeArch = CPUArch . X86_64 ; else if ( nativeCpu . startsWith ( "ppc64" ) || nativeCpu . startsWith ( "powerpc64" ) ) nativeArch = CPUArch . PPC64 ; else if ( nativeCpu . startsWith ( "ppc" ) || nativeCpu . startsWith ( "powerpc" ) ) nativeArch = CPUArch . PPC ; else if ( nativeCpu . contains ( "86" ) ) nativeArch = CPUArch . X86 ; else nativeArch = CPUArch . UNKNOWN ; return nativeArch ; }


Input: Get the OSFamily based on the passed in osName specifier . [CODESPLIT] public static OSFamily getOSFamily ( String osName ) { final OSFamily retval ; if ( osName != null && osName . length ( ) > 0 ) { if ( osName . startsWith ( "Windows" ) ) retval = OSFamily . WINDOWS ; else if ( osName . startsWith ( "Mac" ) ) retval = OSFamily . MAC ; else if ( osName . startsWith ( "Linux" ) ) retval = OSFamily . LINUX ; else retval = OSFamily . UNKNOWN ; } else retval = OSFamily . UNKNOWN ; return retval ; }


Input: Return an OS Family from parsing a GNU autoconf triple . [CODESPLIT] public static OSFamily getOSFamilyFromGNUString ( String gnuString ) { final String nativeOs = ( gnuString != null ? gnuString . toLowerCase ( ) : "" ) ; final OSFamily retval ; if ( nativeOs . startsWith ( "mingw" ) || nativeOs . startsWith ( "cygwin" ) ) retval = OSFamily . WINDOWS ; else if ( nativeOs . startsWith ( "darwin" ) ) retval = OSFamily . MAC ; else if ( nativeOs . startsWith ( "linux" ) ) retval = OSFamily . LINUX ; else retval = OSFamily . UNKNOWN ; return retval ; }


Input: Get a string representation of the time stamp for this { @link Media } . The format of the resulting string is specified by the format parameter . See { @link java . util . Formatter } for details on how to specify formats however a good place to start is with the following format : <b > %1$tH : %1$tM : %1$tS . %1$tL< / b > [CODESPLIT] public String getFormattedTimeStamp ( String format ) { String retval = null ; java . util . Formatter formatter = new java . util . Formatter ( ) ; try { Rational timeBase = getTimeBase ( ) ; if ( timeBase == null ) timeBase = Rational . make ( 1 , ( int ) Global . DEFAULT_PTS_PER_SECOND ) ; retval = formatter . format ( format , ( long ) ( getTimeStamp ( ) * timeBase . getDouble ( ) * 1000 ) + TIME_OFFSET ) . toString ( ) ; timeBase . delete ( ) ; } finally { formatter . close ( ) ; } return retval ; }


Input:
Get the time base that time stamps of this object are represented in .

 Caller must release the returned value .

 [CODESPLIT] public Rational getTimeBase ( ) { long cPtr = VideoJNI . Media_getTimeBase ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Rational ( cPtr , false ) ; }


Input:
Opens a file and plays the audio from it on the speakers . [CODESPLIT] private static void playSound ( String filename ) throws InterruptedException , IOException , LineUnavailableException { /*
     * Start by creating a container object, in this case a demuxer since
     * we are reading, to get audio data from.
     */ Demuxer demuxer = Demuxer . make ( ) ; /*
     * Open the demuxer with the filename passed on.
     */ demuxer . open ( filename , null , false , true , null , null ) ; /*
     * Query how many streams the call to open found
     */ int numStreams = demuxer . getNumStreams ( ) ; /*
     * Iterate through the streams to find the first audio stream
     */ int audioStreamId = - 1 ; Decoder audioDecoder = null ; for ( int i = 0 ; i < numStreams ; i ++ ) { final DemuxerStream stream = demuxer . getStream ( i ) ; final Decoder decoder = stream . getDecoder ( ) ; if ( decoder != null && decoder . getCodecType ( ) == MediaDescriptor . Type . MEDIA_AUDIO ) { audioStreamId = i ; audioDecoder = decoder ; // stop at the first one. break ; } } if ( audioStreamId == - 1 ) throw new RuntimeException ( "could not find audio stream in container: " + filename ) ; /*
     * Now we have found the audio stream in this file.  Let's open up our decoder so it can
     * do work.
     */ audioDecoder . open ( null , null ) ; /*
     * We allocate a set of samples with the same number of channels as the
     * coder tells us is in this buffer.
     */ final MediaAudio samples = MediaAudio . make ( audioDecoder . getFrameSize ( ) , audioDecoder . getSampleRate ( ) , audioDecoder . getChannels ( ) , audioDecoder . getChannelLayout ( ) , audioDecoder . getSampleFormat ( ) ) ; /*
     * A converter object we'll use to convert Humble Audio to a format that
     * Java Audio can actually play. The details are complicated, but essentially
     * this converts any audio format (represented in the samples object) into
     * a default audio format suitable for Java's speaker system (which will
     * be signed 16-bit audio, stereo (2-channels), resampled to 22,050 samples
     * per second).
     */ final MediaAudioConverter converter = MediaAudioConverterFactory . createConverter ( MediaAudioConverterFactory . DEFAULT_JAVA_AUDIO , samples ) ; /*
     * An AudioFrame is a wrapper for the Java Sound system that abstracts away
     * some stuff. Go read the source code if you want -- it's not very complicated.
     */ final AudioFrame audioFrame = AudioFrame . make ( converter . getJavaFormat ( ) ) ; if ( audioFrame == null ) throw new LineUnavailableException ( ) ; /* We will use this to cache the raw-audio we pass to and from
     * the java sound system.
     */ ByteBuffer rawAudio = null ; /*
     * Now, we start walking through the container looking at each packet. This
     * is a decoding loop, and as you work with Humble you'll write a lot
     * of these.
     *
     * Notice how in this loop we reuse all of our objects to avoid
     * reallocating them. Each call to Humble resets objects to avoid
     * unnecessary reallocation.
     */ final MediaPacket packet = MediaPacket . make ( ) ; while ( demuxer . read ( packet ) >= 0 ) { /*
       * Now we have a packet, let's see if it belongs to our audio stream
       */ if ( packet . getStreamIndex ( ) == audioStreamId ) { /*
         * A packet can actually contain multiple sets of samples (or frames of samples
         * in audio-decoding speak).  So, we may need to call decode audio multiple
         * times at different offsets in the packet's data.  We capture that here.
         */ int offset = 0 ; int bytesRead = 0 ; do { bytesRead += audioDecoder . decode ( samples , packet , offset ) ; if ( samples . isComplete ( ) ) { rawAudio = converter . toJavaAudio ( rawAudio , samples ) ; audioFrame . play ( rawAudio ) ; } offset += bytesRead ; } while ( offset < packet . getSize ( ) ) ; } } // Some audio decoders (especially advanced ones) will cache // audio data before they begin decoding, so when you are done you need // to flush them. The convention to flush Encoders or Decoders in Humble Video // is to keep passing in null until incomplete samples or packets are returned. do { audioDecoder . decode ( samples , null , 0 ) ; if ( samples . isComplete ( ) ) { rawAudio = converter . toJavaAudio ( rawAudio , samples ) ; audioFrame . play ( rawAudio ) ; } } while ( samples . isComplete ( ) ) ; // It is good practice to close demuxers when you're done to free // up file handles. Humble will EVENTUALLY detect if nothing else // references this demuxer and close it then, but get in the habit // of cleaning up after yourself, and your future girlfriend/boyfriend // will appreciate it. demuxer . close ( ) ; // similar with the demuxer, for the audio playback stuff, clean up after yourself. audioFrame . dispose ( ) ; }


Input: Takes a media container ( file ) as the first argument opens it opens up the default audio device on your system and plays back the audio . [CODESPLIT] public static void main ( String [ ] args ) throws InterruptedException , IOException , LineUnavailableException { final Options options = new Options ( ) ; options . addOption ( "h" , "help" , false , "displays help" ) ; options . addOption ( "v" , "version" , false , "version of this library" ) ; final CommandLineParser parser = new org . apache . commons . cli . BasicParser ( ) ; try { final CommandLine cmd = parser . parse ( options , args ) ; if ( cmd . hasOption ( "version" ) ) { // let's find what version of the library we're running final String version = io . humble . video_native . Version . getVersionInfo ( ) ; System . out . println ( "Humble Version: " + version ) ; } else if ( cmd . hasOption ( "help" ) || args . length == 0 ) { final HelpFormatter formatter = new HelpFormatter ( ) ; formatter . printHelp ( DecodeAndPlayAudio . class . getCanonicalName ( ) + " <filename>" , options ) ; } else { final String [ ] parsedArgs = cmd . getArgs ( ) ; for ( String arg : parsedArgs ) playSound ( arg ) ; } } catch ( ParseException e ) { System . err . println ( "Exception parsing command line: " + e . getLocalizedMessage ( ) ) ; } }


Input: Releases any underlying native memory and marks this object as invalid . <p > Normally Ferry manages when to release native memory . < / p > <p > In the unlikely event you want to control EXACTLY when a native object is released each Humble object has a { [CODESPLIT] public void delete ( ) { if ( swigCPtr != 0 ) { // assigning to an object removes an incorrect java // compiler warning for some // generated files Object object = this ; if ( object instanceof RefCounted && mRefCounter != null ) { mRefCounter . delete ( ) ; } else if ( swigCMemOwn ) { swigCMemOwn = false ; } } mJavaRefCount = null ; mRefCounter = null ; mObjectToForceFinalize = null ; mLifecycleReference = null ; swigCPtr = 0 ; }


Input: @deprecated Use { @link JNILibrary } instead . [CODESPLIT] @ Deprecated public static void loadLibrary ( String aLibraryName , Long aMajorVersion ) { getInstance ( ) . loadLibrary0 ( aLibraryName , aMajorVersion ) ; }


Input: This is the method that actually loads the library . It maintains an object level lock and since this class only allows a singleton object that is a class - level lock . That means if you re loading a library on one thread other threads will block until it finishes . [CODESPLIT] synchronized void loadLibrary0 ( String aLibraryName , Long aMajorVersion ) { if ( alreadyLoadedLibrary ( aLibraryName , aMajorVersion ) ) // our work is done. return ; List < String > libCandidates = getLibraryCandidates ( aLibraryName , aMajorVersion ) ; if ( libCandidates != null && libCandidates . size ( ) > 0 && ! loadCandidateLibrary ( aLibraryName , aMajorVersion , libCandidates ) ) { // finally, try the System.loadLibrary call try { System . loadLibrary ( aLibraryName ) ; } catch ( UnsatisfiedLinkError e ) { log . error ( "Could not load library: {}; version: {}." , aLibraryName , aMajorVersion == null ? "" : aMajorVersion ) ; throw e ; } // and if we get here it means we successfully loaded since no // exception was thrown. Add our library to the cache. setLoadedLibrary ( aLibraryName , aMajorVersion ) ; } log . trace ( "Successfully Loaded library: {}; Version: {}" , aLibraryName , aMajorVersion ) ; }


Input: Tell the cache that we ve loaded this version . [CODESPLIT] void setLoadedLibrary ( String aLibraryName , Long aMajorVersion ) { Set < Long > foundVersions = mLoadedLibraries . get ( aLibraryName ) ; if ( foundVersions == null ) { foundVersions = new HashSet < Long > ( ) ; mLoadedLibraries . put ( aLibraryName , foundVersions ) ; } foundVersions . add ( aMajorVersion ) ; }


Input: Iterates through the set of aLibCandidates until it succeeds in loading a library . If it succeeds it lets the cache know . [CODESPLIT] boolean loadCandidateLibrary ( String aLibraryName , Long aMajorVersion , List < String > aLibCandidates ) { boolean retval = false ; for ( String candidate : aLibCandidates ) { log . trace ( "Attempt: library load of library: {}; version: {}: relative path: {}" , new Object [ ] { aLibraryName , aMajorVersion == null ? "<unspecified>" : aMajorVersion . longValue ( ) , candidate } ) ; File candidateFile = new File ( candidate ) ; if ( candidateFile . exists ( ) ) { String absPath = candidateFile . getAbsolutePath ( ) ; try { log . trace ( "Attempt: library load of library: {}; version: {}: absolute path: {}" , new Object [ ] { aLibraryName , aMajorVersion == null ? "<unspecified>" : aMajorVersion . longValue ( ) , absPath } ) ; // Here's where we attempt the actual load. System . load ( absPath ) ; log . trace ( "Success: library load of library: {}; version: {}: absolute path: {}" , new Object [ ] { aLibraryName , aMajorVersion == null ? "<unspecified>" : aMajorVersion . longValue ( ) , absPath } ) ; // if we got here, we loaded successfully setLoadedLibrary ( aLibraryName , aMajorVersion ) ; retval = true ; break ; } catch ( UnsatisfiedLinkError e ) { log . warn ( "Failure: library load of library: {}; version: {}: absolute path: {}; error: {}" , new Object [ ] { aLibraryName , aMajorVersion == null ? "<unspecified>" : aMajorVersion . longValue ( ) , absPath , e } ) ; } catch ( SecurityException e ) { log . warn ( "Failure: library load of library: {}; version: {}: absolute path: {}; error: {}" , new Object [ ] { aLibraryName , aMajorVersion == null ? "<unspecified>" : aMajorVersion . longValue ( ) , absPath , e } ) ; } } } return retval ; }


Input: For a given library and the OS we re running on this method generates a list of potential absolute file paths that { @link #loadCandidateLibrary ( String Long String [] ) } should attempt ( in order ) to load . This method will not check for existence and readability of the file we re attempting to load . [CODESPLIT] List < String > getLibraryCandidates ( String aLibraryName , Long aMajorVersion ) { final List < String > retval = new LinkedList < String > ( ) ; // Note: when done each of these variables must be set to a non-null, non // empty string array final String [ ] prefixes ; final String [ ] suffixes ; final String [ ] preSuffixVersions ; final String [ ] postSuffixVersions ; switch ( getOS ( ) ) { case Unknown : case Linux : prefixes = new String [ ] { "lib" , "" } ; suffixes = new String [ ] { ".so" } ; preSuffixVersions = new String [ ] { "" } ; postSuffixVersions = ( aMajorVersion == null ? new String [ ] { "" } : new String [ ] { "." + aMajorVersion . longValue ( ) } ) ; break ; case Windows : prefixes = new String [ ] { "lib" , "" , "cyg" } ; suffixes = new String [ ] { ".dll" } ; preSuffixVersions = ( aMajorVersion == null ? new String [ ] { "" } : new String [ ] { "-" + aMajorVersion . longValue ( ) } ) ; postSuffixVersions = new String [ ] { "" } ; break ; case MacOSX : prefixes = new String [ ] { "lib" , "" } ; suffixes = new String [ ] { ".dylib" } ; preSuffixVersions = ( aMajorVersion == null ? new String [ ] { "" } : new String [ ] { "." + aMajorVersion . longValue ( ) } ) ; postSuffixVersions = new String [ ] { "" } ; break ; default : // really no cases should get here prefixes = null ; suffixes = null ; preSuffixVersions = null ; postSuffixVersions = null ; break ; } initializeSearchPaths ( ) ; // First check the versioned paths if ( aMajorVersion != null ) { for ( String directory : mJavaPropPaths ) { generateFileNames ( retval , directory , aLibraryName , prefixes , suffixes , preSuffixVersions , postSuffixVersions , true ) ; } for ( String directory : mJavaEnvPaths ) { generateFileNames ( retval , directory , aLibraryName , prefixes , suffixes , preSuffixVersions , postSuffixVersions , true ) ; } } for ( String directory : mJavaPropPaths ) { generateFileNames ( retval , directory , aLibraryName , prefixes , suffixes , preSuffixVersions , postSuffixVersions , false ) ; } for ( String directory : mJavaEnvPaths ) { generateFileNames ( retval , directory , aLibraryName , prefixes , suffixes , preSuffixVersions , postSuffixVersions , false ) ; } return retval ; }


Input: Initialize the paths we ll search for libraries in . [CODESPLIT] private void initializeSearchPaths ( ) { String pathVar = null ; if ( mJavaPropPaths == null ) { pathVar = System . getProperty ( "java.library.path" , "" ) ; log . trace ( "property java.library.path: {}" , pathVar ) ; mJavaPropPaths = getEntitiesFromPath ( pathVar ) ; } if ( mJavaEnvPaths == null ) { String envVar = getSystemRuntimeLibraryPathVar ( ) ; pathVar = System . getenv ( envVar ) ; log . trace ( "OS environment runtime shared library path ({}): {}" , envVar , pathVar ) ; mJavaEnvPaths = getEntitiesFromPath ( pathVar ) ; } }


Input: Checks our cache to see if we ve already loaded this library . [CODESPLIT] boolean alreadyLoadedLibrary ( String aLibraryName , Long aMajorVersion ) { boolean retval = false ; Set < Long > foundVersions = mLoadedLibraries . get ( aLibraryName ) ; if ( foundVersions != null ) { // we found at least some versions if ( aMajorVersion == null || foundVersions . contains ( aMajorVersion ) ) { retval = true ; } else { log . warn ( "Attempting load of {}, version {}, but already loaded verions: {}." + "  We will attempt to load the specified version but behavior is undefined" , new Object [ ] { aLibraryName , aMajorVersion , foundVersions . toArray ( ) } ) ; } } return retval ; }


Input:
Create a Decoder that will use the given Codec .

 [CODESPLIT] public static Decoder make ( Codec codec ) { long cPtr = VideoJNI . Decoder_make__SWIG_0 ( Codec . getCPtr ( codec ) , codec ) ; return ( cPtr == 0 ) ? null : new Decoder ( cPtr , false ) ; }


Input: Creates a Decoder from a given Coder ( either an encoder or a decoder ) . <br > [CODESPLIT] public static Decoder make ( Coder src ) { long cPtr = VideoJNI . Decoder_make__SWIG_1 ( Coder . getCPtr ( src ) , src ) ; return ( cPtr == 0 ) ? null : new Decoder ( cPtr , false ) ; }


Input:
Decode this packet into output . It will
 try to fill up the audio samples object starting
 from the byteOffset inside this packet .

 The caller is responsible for allocating the
 MediaAudio object . This function will overwrite
 any data in the samples object .

 [CODESPLIT] public int decodeAudio ( MediaAudio output , MediaPacket packet , int byteOffset ) { return VideoJNI . Decoder_decodeAudio ( swigCPtr , this , MediaAudio . getCPtr ( output ) , output , MediaPacket . getCPtr ( packet ) , packet , byteOffset ) ; }


Input:
Decode this packet into output .

 The caller is responsible for allocating the
 MediaPicture object . This function will potentially
 overwrite any data in the frame object but
 you should pass the same MediaPicture into this function
 repeatedly until Media . isComplete () is true .

 Note on memory for MediaPicture : For a multitude of reasons
 if you created MediaPicture from a buffer decodeVideo will discard
 it and replace it with a buffer that is aligned correctly for different
 CPUs and different codecs . If you must have a copy of the image data
 in memory managed by you then pass in a MediaPicture allocated without
 a buffer to DecodeVideo and then copy that into your own media picture .

 [CODESPLIT] public int decodeVideo ( MediaPicture output , MediaPacket packet , int byteOffset ) { return VideoJNI . Decoder_decodeVideo ( swigCPtr , this , MediaPicture . getCPtr ( output ) , output , MediaPacket . getCPtr ( packet ) , packet , byteOffset ) ; }


Input:
Decode this packet into output . It will
 try to fill up the media object starting
 from the byteOffset inside this packet .

 The caller is responsible for allocating the
 correct underlying Media object . This function will overwrite
 any data in the samples object .

 [CODESPLIT] public int decode ( MediaSampled output , MediaPacket packet , int byteOffset ) { return VideoJNI . Decoder_decode ( swigCPtr , this , MediaSampled . getCPtr ( output ) , output , MediaPacket . getCPtr ( packet ) , packet , byteOffset ) ; }


Input:
Records the screen [CODESPLIT] private static void recordScreen ( String filename , String formatname , String codecname , int duration , int snapsPerSecond ) throws AWTException , InterruptedException , IOException { /**
     * Set up the AWT infrastructure to take screenshots of the desktop.
     */ final Robot robot = new Robot ( ) ; final Toolkit toolkit = Toolkit . getDefaultToolkit ( ) ; final Rectangle screenbounds = new Rectangle ( toolkit . getScreenSize ( ) ) ; final Rational framerate = Rational . make ( 1 , snapsPerSecond ) ; /** First we create a muxer using the passed in filename and formatname if given. */ final Muxer muxer = Muxer . make ( filename , null , formatname ) ; /** Now, we need to decide what type of codec to use to encode video. Muxers
     * have limited sets of codecs they can use. We're going to pick the first one that
     * works, or if the user supplied a codec name, we're going to force-fit that
     * in instead.
     */ final MuxerFormat format = muxer . getFormat ( ) ; final Codec codec ; if ( codecname != null ) { codec = Codec . findEncodingCodecByName ( codecname ) ; } else { codec = Codec . findEncodingCodec ( format . getDefaultVideoCodecId ( ) ) ; } /**
     * Now that we know what codec, we need to create an encoder
     */ Encoder encoder = Encoder . make ( codec ) ; /**
     * Video encoders need to know at a minimum:
     *   width
     *   height
     *   pixel format
     * Some also need to know frame-rate (older codecs that had a fixed rate at which video files could
     * be written needed this). There are many other options you can set on an encoder, but we're
     * going to keep it simpler here.
     */ encoder . setWidth ( screenbounds . width ) ; encoder . setHeight ( screenbounds . height ) ; // We are going to use 420P as the format because that's what most video formats these days use final PixelFormat . Type pixelformat = PixelFormat . Type . PIX_FMT_YUV420P ; encoder . setPixelFormat ( pixelformat ) ; encoder . setTimeBase ( framerate ) ; /** An annoynace of some formats is that they need global (rather than per-stream) headers,
     * and in that case you have to tell the encoder. And since Encoders are decoupled from
     * Muxers, there is no easy way to know this beyond
     */ if ( format . getFlag ( MuxerFormat . Flag . GLOBAL_HEADER ) ) encoder . setFlag ( Encoder . Flag . FLAG_GLOBAL_HEADER , true ) ; /** Open the encoder. */ encoder . open ( null , null ) ; /** Add this stream to the muxer. */ muxer . addNewStream ( encoder ) ; /** And open the muxer for business. */ muxer . open ( null , null ) ; /** Next, we need to make sure we have the right MediaPicture format objects
     * to encode data with. Java (and most on-screen graphics programs) use some
     * variant of Red-Green-Blue image encoding (a.k.a. RGB or BGR). Most video
     * codecs use some variant of YCrCb formatting. So we're going to have to
     * convert. To do that, we'll introduce a MediaPictureConverter object later. object.
     */ MediaPictureConverter converter = null ; final MediaPicture picture = MediaPicture . make ( encoder . getWidth ( ) , encoder . getHeight ( ) , pixelformat ) ; picture . setTimeBase ( framerate ) ; /** Now begin our main loop of taking screen snaps.
     * We're going to encode and then write out any resulting packets. */ final MediaPacket packet = MediaPacket . make ( ) ; for ( int i = 0 ; i < duration / framerate . getDouble ( ) ; i ++ ) { /** Make the screen capture && convert image to TYPE_3BYTE_BGR */ final BufferedImage screen = convertToType ( robot . createScreenCapture ( screenbounds ) , BufferedImage . TYPE_3BYTE_BGR ) ; /** This is LIKELY not in YUV420P format, so we're going to convert it using some handy utilities. */ if ( converter == null ) converter = MediaPictureConverterFactory . createConverter ( screen , picture ) ; converter . toPicture ( picture , screen , i ) ; do { encoder . encode ( packet , picture ) ; if ( packet . isComplete ( ) ) muxer . write ( packet , false ) ; } while ( packet . isComplete ( ) ) ; /** now we'll sleep until it's time to take the next snapshot. */ Thread . sleep ( ( long ) ( 1000 * framerate . getDouble ( ) ) ) ; } /** Encoders, like decoders, sometimes cache pictures so it can do the right key-frame optimizations.
     * So, they need to be flushed as well. As with the decoders, the convention is to pass in a null
     * input until the output is not complete.
     */ do { encoder . encode ( packet , null ) ; if ( packet . isComplete ( ) ) muxer . write ( packet , false ) ; } while ( packet . isComplete ( ) ) ; /** Finally, let's clean up after ourselves. */ muxer . close ( ) ; }


Input: Explicitly deletes the underlying native storage used by the object this object references . The underlying native object is now no long valid and attempts to use it could cause unspecified behavior . [CODESPLIT] public void delete ( ) { // acquire lock for minimum time final long swigPtr = mSwigCPtr . getAndSet ( 0 ) ; if ( swigPtr != 0 ) { if ( mJavaRefCount . decrementAndGet ( ) == 0 ) { // log.debug("deleting: {}; {}", this, mSwigCPtr); FerryJNI . RefCounted_release ( swigPtr , null ) ; } // Free the memory manager we use mMemAllocator = null ; } }


Input:
Adds audio to this source . NOTE : If you had audio to a FilterSource
 be careful with re - using or rewriting the underlying data . Filters will
 try hard to avoid copying data so if you change the data out from under
 them unexpected results can occur .
 [CODESPLIT] public void addAudio ( MediaAudio audio ) { VideoJNI . FilterAudioSource_addAudio ( swigCPtr , this , MediaAudio . getCPtr ( audio ) , audio ) ; }


Input:
Resample in to out based on the resampler parameters .

 Resamples the in media based on the parameters set when
 this resampler was constructed .

 [CODESPLIT] public int resample ( MediaSampled out , MediaSampled in ) { return VideoJNI . MediaResampler_resample ( swigCPtr , this , MediaSampled . getCPtr ( out ) , out , MediaSampled . getCPtr ( in ) , in ) ; }


Input: Return a sample format corresponding to name or SAMPLE_FMT_NONE<br > on error . [CODESPLIT] public static AudioFormat . Type getFormat ( String name ) { return AudioFormat . Type . swigToEnum ( VideoJNI . AudioFormat_getFormat ( name ) ) ; }


Input:
Return the planar&lt ; - &gt ; packed alternative form of the given sample format or
 SAMPLE_FMT_NONE on error . If the passed sample_fmt is already in the
 requested planar / packed format the format returned is the same as the
 input . [CODESPLIT] public static AudioFormat . Type getAlternateSampleFormat ( AudioFormat . Type sample_fmt , boolean planar ) { return AudioFormat . Type . swigToEnum ( VideoJNI . AudioFormat_getAlternateSampleFormat ( sample_fmt . swigValue ( ) , planar ) ) ; }


Input:
Get the packed alternative form of the given sample format .

 If the passed sample_fmt is already in packed format the format returned is
 the same as the input .

 [CODESPLIT] public static AudioFormat . Type getPackedSampleFormat ( AudioFormat . Type sample_fmt ) { return AudioFormat . Type . swigToEnum ( VideoJNI . AudioFormat_getPackedSampleFormat ( sample_fmt . swigValue ( ) ) ) ; }


Input:
Get the planar alternative form of the given sample format .

 If the passed sample_fmt is already in planar format the format returned is
 the same as the input .

 [CODESPLIT] public static AudioFormat . Type getPlanarSampleFormat ( AudioFormat . Type sample_fmt ) { return AudioFormat . Type . swigToEnum ( VideoJNI . AudioFormat_getPlanarSampleFormat ( sample_fmt . swigValue ( ) ) ) ; }


Input: Get the size of a buffer in bytes that would be required to hold the<br > number of samples of audio in the given format and with the given number of channels . [CODESPLIT] public static int getBufferSizeNeeded ( int numSamples , int numChannels , AudioFormat . Type format ) { return VideoJNI . AudioFormat_getBufferSizeNeeded ( numSamples , numChannels , format . swigValue ( ) ) ; }


Input:
Get the size of a plane of audio bytes that would be required to hold the
 number of samples of audio in the given format and with the given number of channels .

 If format is packed then this method returns the same number as #getBufferSizeNeeded ( int int Type ) .

 [CODESPLIT] public static int getDataPlaneSizeNeeded ( int numSamples , int numChannels , AudioFormat . Type format ) { return VideoJNI . AudioFormat_getDataPlaneSizeNeeded ( numSamples , numChannels , format . swigValue ( ) ) ; }


Input:
Creates a new muxer .

 One of the three passed in parameter must be non - null . If the muxer requires a URL to write to
 then that must be specified .

 [CODESPLIT] public static Muxer make ( String filename , MuxerFormat format , String formatName ) { long cPtr = VideoJNI . Muxer_make ( filename , MuxerFormat . getCPtr ( format ) , format , formatName ) ; return ( cPtr == 0 ) ? null : new Muxer ( cPtr , false ) ; }


Input: Get the MuxerFormat associated with this Muxer<br > or null if unknown . [CODESPLIT] public MuxerFormat getFormat ( ) { long cPtr = VideoJNI . Muxer_getFormat ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new MuxerFormat ( cPtr , false ) ; }


Input:
Open the Muxer and write any headers .

 [CODESPLIT] public void open ( KeyValueBag inputOptions , KeyValueBag outputOptions ) throws java . lang . InterruptedException , java . io . IOException { VideoJNI . Muxer_open ( swigCPtr , this , KeyValueBag . getCPtr ( inputOptions ) , inputOptions , KeyValueBag . getCPtr ( outputOptions ) , outputOptions ) ; }


Input:
Adds a new stream that will have packets written to it .

 Note on thread safety : Callers must ensure that the coder is not encoding or decoding
 packets at the same time that Muxer#open or Muxer#close is being called .

 [CODESPLIT] public MuxerStream addNewStream ( Coder coder ) { long cPtr = VideoJNI . Muxer_addNewStream ( swigCPtr , this , Coder . getCPtr ( coder ) , coder ) ; return ( cPtr == 0 ) ? null : new MuxerStream ( cPtr , false ) ; }


Input: Get the MuxerStream at the given position . [CODESPLIT] public MuxerStream getStream ( int position ) throws java . lang . InterruptedException , java . io . IOException { long cPtr = VideoJNI . Muxer_getStream ( swigCPtr , this , position ) ; return ( cPtr == 0 ) ? null : new MuxerStream ( cPtr , false ) ; }


Input:
Writes the given packet to the Muxer .

 [CODESPLIT] public boolean write ( MediaPacket packet , boolean forceInterleave ) { return VideoJNI . Muxer_write ( swigCPtr , this , MediaPacket . getCPtr ( packet ) , packet , forceInterleave ) ; }


Input: JNIHelper . swg : End generated code [CODESPLIT] public static Mutex make ( ) { long cPtr = FerryJNI . Mutex_make ( ) ; return ( cPtr == 0 ) ? null : new Mutex ( cPtr , false ) ; }


Input:
Get the CodecId for the n th codec supported by this container .

 [CODESPLIT] protected Codec . ID getSupportedCodecId ( int n ) { return Codec . ID . swigToEnum ( VideoJNI . DemuxerFormat_getSupportedCodecId ( swigCPtr , this , n ) ) ; }


Input: Find DemuxerFormat based on the short name of the input format . <br > [CODESPLIT] public static DemuxerFormat findFormat ( String shortName ) { long cPtr = VideoJNI . DemuxerFormat_findFormat ( shortName ) ; return ( cPtr == 0 ) ? null : new DemuxerFormat ( cPtr , false ) ; }


Input:
Return an object for the DemuxerFormats at the given index .

 [CODESPLIT] protected static DemuxerFormat getFormat ( int index ) { long cPtr = VideoJNI . DemuxerFormat_getFormat ( index ) ; return ( cPtr == 0 ) ? null : new DemuxerFormat ( cPtr , false ) ; }


Input:
The number of streams in this container .

 If this container is a Source this will query the stream and find out
 how many streams are in it .

 If the current thread is interrupted while this blocking method
 is running the method will return with a negative value .
 To check if the method exited because of an interruption
 pass the return value to Error#make ( int ) and then
 check Error#getType () to see if it is
 Error . Type#ERROR_INTERRUPTED .

 [CODESPLIT] public int getNumStreams ( ) throws java . lang . InterruptedException , java . io . IOException { return VideoJNI . Container_getNumStreams ( swigCPtr , this ) ; }


Input: Get the Coder that this stream was created with . <br > Note : this can be either an Encoder or a Decoder . [CODESPLIT] public Coder getCoder ( ) { long cPtr = VideoJNI . MuxerStream_getCoder ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Coder ( cPtr , false ) ; }


Input: Get the Muxer that this stream belongs to . [CODESPLIT] public Muxer getMuxer ( ) { long cPtr = VideoJNI . MuxerStream_getMuxer ( swigCPtr , this ) ; return ( cPtr == 0 ) ? null : new Muxer ( cPtr , false ) ; }


Input: Creates a signed SetScript object . [CODESPLIT] public static SetScriptTransaction makeScriptTx ( PrivateKeyAccount sender , String script , byte chainId , long fee , long timestamp ) { return new SetScriptTransaction ( sender , script , chainId , fee , timestamp ) ; }


Input: Decodes the given base58 string into the original data bytes . [CODESPLIT] public static byte [ ] decode ( String input ) throws IllegalArgumentException { if ( input . startsWith ( "base58:" ) ) input = input . substring ( 7 ) ; if ( input . length ( ) == 0 ) return new byte [ 0 ] ; // Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits). byte [ ] input58 = new byte [ input . length ( ) ] ; for ( int i = 0 ; i < input . length ( ) ; ++ i ) { char c = input . charAt ( i ) ; int digit = c < 128 ? INDEXES [ c ] : - 1 ; if ( digit < 0 ) { throw new IllegalArgumentException ( "Illegal character " + c + " at position " + i ) ; } input58 [ i ] = ( byte ) digit ; } // Count leading zeros. int zeros = 0 ; while ( zeros < input58 . length && input58 [ zeros ] == 0 ) { ++ zeros ; } // Convert base-58 digits to base-256 digits. byte [ ] decoded = new byte [ input . length ( ) ] ; int outputStart = decoded . length ; for ( int inputStart = zeros ; inputStart < input58 . length ; ) { decoded [ -- outputStart ] = divmod ( input58 , inputStart , 58 , 256 ) ; if ( input58 [ inputStart ] == 0 ) { ++ inputStart ; // optimization - skip leading zeros } } // Ignore extra leading zeroes that were added during the calculation. while ( outputStart < decoded . length && decoded [ outputStart ] == 0 ) { ++ outputStart ; } // Return decoded data (including original number of leading zeros). return Arrays . copyOfRange ( decoded , outputStart - zeros , decoded . length ) ; }


Input: Generates a 15 - word random seed . This method implements the BIP - 39 algorithm with 160 bits of entropy . [CODESPLIT] public static String generateSeed ( ) { byte [ ] bytes = new byte [ 21 ] ; new SecureRandom ( ) . nextBytes ( bytes ) ; byte [ ] rhash = hash ( bytes , 0 , 20 , SHA256 ) ; bytes [ 20 ] = rhash [ 0 ] ; BigInteger rand = new BigInteger ( bytes ) ; BigInteger mask = new BigInteger ( new byte [ ] { 0 , 0 , 7 , - 1 } ) ; // 11 lower bits StringBuilder sb = new StringBuilder ( ) ; for ( int i = 0 ; i < 15 ; i ++ ) { sb . append ( i > 0 ? ' ' : "" ) . append ( SEED_WORDS [ rand . and ( mask ) . intValue ( ) ] ) ; rand = rand . shiftRight ( 11 ) ; } return sb . toString ( ) ; }


Input: Returns object by its ID . [CODESPLIT] public Transaction getTransaction ( String txId ) throws IOException { return wavesJsonMapper . convertValue ( send ( "/transactions/info/" + txId ) , Transaction . class ) ; }


Input: Returns transactions by address with limit . [CODESPLIT] public List < Transaction > getAddressTransactions ( String address , int limit ) throws IOException { return getAddressTransactions ( address , limit , null ) ; }


Input: Returns transactions by address with limit after passed transaction id . [CODESPLIT] public List < Transaction > getAddressTransactions ( String address , int limit , String after ) throws IOException { String requestUrl = String . format ( "/transactions/address/%s/limit/%d" , address , limit ) ; if ( after != null ) { requestUrl += String . format ( "?after=%s" , after ) ; } return wavesJsonMapper . < List < List < Transaction > > > convertValue ( send ( requestUrl ) , new TypeReference < List < List < Transaction > > > ( ) { } ) . get ( 0 ) ; }


Input: Returns seq of block headers [CODESPLIT] public List < BlockHeader > getBlockHeaderSeq ( int from , int to ) throws IOException { String path = String . format ( "/blocks/headers/seq/%s/%s" , from , to ) ; HttpResponse r = exec ( request ( path ) ) ; return parse ( r , BLOCK_HEADER_LIST ) ; }


Input: Returns block by its signature . [CODESPLIT] public Block getBlock ( String signature ) throws IOException { return wavesJsonMapper . convertValue ( send ( "/blocks/signature/" + signature ) , Block . class ) ; }


Input: Sends a signed object and returns its ID . [CODESPLIT] public String send ( Transaction tx ) throws IOException { return parse ( exec ( request ( tx ) ) , "id" ) . asText ( ) ; }


Input: Sets a validating script for an account . [CODESPLIT] public String setScript ( PrivateKeyAccount from , String script , byte chainId , long fee ) throws IOException { return send ( Transactions . makeScriptTx ( from , compileScript ( script ) , chainId , fee ) ) ; }


Input: Compiles a script . [CODESPLIT] public String compileScript ( String script ) throws IOException { if ( script == null || script . isEmpty ( ) ) { return null ; } HttpPost request = new HttpPost ( uri . resolve ( "/utils/script/compile" ) ) ; request . setEntity ( new StringEntity ( script ) ) ; return parse ( exec ( request ) , "script" ) . asText ( ) ; }


Input: write the contents of a given object [CODESPLIT] @ Override public void writeObject ( FSTObjectOutput out , Object toWrite , FSTClazzInfo clzInfo , FSTClazzInfo . FSTFieldInfo referencedBy , int streamPosition ) throws IOException { FSTStruct str = ( FSTStruct ) toWrite ; if ( ! str . isOffHeap ( ) ) { str = str . toOffHeap ( ) ; } int byteSize = str . getByteSize ( ) ; out . writeInt ( byteSize ) ; if ( COMPRESS ) { long base = str . ___offset ; int intsiz = byteSize / 4 ; for ( int i = 0 ; i < intsiz ; i ++ ) { int value = str . getInt ( ) ; value = ( value << 1 ) ^ ( value >> 31 ) ; str . ___offset += 4 ; while ( ( value & 0xFFFFFF80 ) != 0L ) { out . writeByte ( ( value & 0x7F ) | 0x80 ) ; value >>>= 7 ; } out . writeByte ( value & 0x7F ) ; } int remainder = byteSize & 3 ; for ( int i = 0 ; i < remainder ; i ++ ) { byte aByte = str . getByte ( ) ; out . writeByte ( aByte ) ; str . ___offset ++ ; } str . ___offset = base ; } else { byte b [ ] = new byte [ byteSize ] ; // fixme: cache threadlocal str . getBase ( ) . getArr ( str . getOffset ( ) , b , 0 , byteSize ) ; out . write ( b , 0 , byteSize ) ; } }


Input: len < 127 !!!!! [CODESPLIT] @ Override public String readStringAsc ( ) throws IOException { int len = readFInt ( ) ; if ( ascStringCache == null || ascStringCache . length < len ) ascStringCache = new byte [ len ] ; input . ensureReadAhead ( len ) ; System . arraycopy ( input . buf , input . pos , ascStringCache , 0 , len ) ; input . pos += len ; return new String ( ascStringCache , 0 , 0 , len ) ; }


Input: assumes class header + len already read [CODESPLIT] @ Override public Object readFPrimitiveArray ( Object array , Class componentType , int len ) { try { if ( componentType == byte . class ) { byte [ ] arr = ( byte [ ] ) array ; ensureReadAhead ( arr . length ) ; // fixme: move this stuff to the stream ! System . arraycopy ( input . buf , input . pos , arr , 0 , len ) ; input . pos += len ; return arr ; } else if ( componentType == int . class ) { final int [ ] arr = ( int [ ] ) array ; readFIntArr ( len , arr ) ; return arr ; } else if ( componentType == long . class ) { long [ ] arr = ( long [ ] ) array ; readFLongArr ( len , arr ) ; return arr ; } else if ( componentType == char . class ) { char [ ] arr = ( char [ ] ) array ; for ( int j = 0 ; j < len ; j ++ ) { arr [ j ] = readFChar ( ) ; } return arr ; } else if ( componentType == double . class ) { double [ ] arr = ( double [ ] ) array ; ensureReadAhead ( arr . length * 8 ) ; for ( int j = 0 ; j < len ; j ++ ) { arr [ j ] = readFDouble ( ) ; } return arr ; } else if ( componentType == short . class ) { short [ ] arr = ( short [ ] ) array ; ensureReadAhead ( arr . length * 2 ) ; for ( int j = 0 ; j < len ; j ++ ) { arr [ j ] = readFShort ( ) ; } return arr ; } else if ( componentType == float . class ) { float [ ] arr = ( float [ ] ) array ; ensureReadAhead ( arr . length * 4 ) ; for ( int j = 0 ; j < len ; j ++ ) { arr [ j ] = readFFloat ( ) ; } return arr ; } else if ( componentType == boolean . class ) { boolean [ ] arr = ( boolean [ ] ) array ; ensureReadAhead ( arr . length ) ; for ( int j = 0 ; j < len ; j ++ ) { arr [ j ] = readFByte ( ) == 0 ? false : true ; } return arr ; } else { throw new RuntimeException ( "unexpected primitive type " + componentType . getName ( ) ) ; } } catch ( IOException e ) { LOGGER . log ( FSTLogger . Level . ERROR , "Failed to read primitive array" , e ) ; FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: compressed version [CODESPLIT] public void _readFIntArr ( int len , int [ ] arr ) throws IOException { ensureReadAhead ( 5 * len ) ; final byte buf [ ] = input . buf ; int count = input . pos ; for ( int j = 0 ; j < len ; j ++ ) { final byte head = buf [ count ++ ] ; // -128 = short byte, -127 == 4 byte if ( head > - 127 && head <= 127 ) { arr [ j ] = head ; continue ; } if ( head == - 128 ) { final int ch1 = ( buf [ count ++ ] + 256 ) & 0xff ; final int ch2 = ( buf [ count ++ ] + 256 ) & 0xff ; arr [ j ] = ( short ) ( ( ch1 << 8 ) + ( ch2 << 0 ) ) ; continue ; } else { int ch1 = ( buf [ count ++ ] + 256 ) & 0xff ; int ch2 = ( buf [ count ++ ] + 256 ) & 0xff ; int ch3 = ( buf [ count ++ ] + 256 ) & 0xff ; int ch4 = ( buf [ count ++ ] + 256 ) & 0xff ; arr [ j ] = ( ( ch1 << 24 ) + ( ch2 << 16 ) + ( ch3 << 8 ) + ( ch4 << 0 ) ) ; } } input . pos = count ; }


Input: write prim array no len no tag [CODESPLIT] public void writePrimitiveArray ( Object array , int off , int len ) throws IOException { Class < ? > componentType = array . getClass ( ) . getComponentType ( ) ; if ( componentType == byte . class ) { writeRawBytes ( ( byte [ ] ) array , off , len ) ; } else if ( componentType == char . class ) { writeFCharArr ( ( char [ ] ) array , off , len ) ; } else if ( componentType == short . class ) { writeFShortArr ( ( short [ ] ) array , off , len ) ; } else if ( componentType == int . class ) { writeFIntArr ( ( int [ ] ) array , off , len ) ; } else if ( componentType == double . class ) { writeFDoubleArr ( ( double [ ] ) array , off , len ) ; } else if ( componentType == float . class ) { writeFFloatArr ( ( float [ ] ) array , off , len ) ; } else if ( componentType == long . class ) { writeFLongArr ( ( long [ ] ) array , off , len ) ; } else if ( componentType == boolean . class ) { writeFBooleanArr ( ( boolean [ ] ) array , off , len ) ; } else { throw new RuntimeException ( "expected primitive array" ) ; } }


Input: does not write length just plain bytes [CODESPLIT] public void writeRawBytes ( byte [ ] array , int start , int length ) throws IOException { ensureFree ( ( int ) ( pos + length ) ) ; buffout . set ( pos , array , start , length ) ; pos += length ; }


Input: used to write uncompressed int ( guaranteed length = 4 ) at a ( eventually recent ) position [CODESPLIT] @ Override public void writeInt32At ( int position , int v ) { try { ensureFree ( position + 4 ) ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } buffout . putInt ( position , v ) ; }


Input: writes current buffer to underlying output and resets buffer . [CODESPLIT] @ Override public void flush ( ) throws IOException { if ( outStream != null ) outStream . write ( getBuffer ( ) , 0 , ( int ) pos ) ; pos = 0 ; }


Input: throws FSTBufferTooSmallException in case object does not fit into given range [CODESPLIT] public int toMemory ( Object o , long address , int availableSize ) throws IOException { out . resetForReUse ( ) ; writeTarget . setBase ( address , availableSize ) ; out . writeObject ( o ) ; int written = out . getWritten ( ) ; return written ; }


Input: determines classname tagging . Overrifing can enforce class tags always or ( JSon ) write as special attribute [CODESPLIT] protected void writeClazzTag ( Class expectedClass , Object o ) { if ( expectedClass == o . getClass ( ) ) { out . writeString ( "{" ) ; } else { String stringForType = mapper . getStringForType ( o . getClass ( ) ) ; out . writeString ( stringForType + " {" ) ; } }


Input: in case readClass already reads full minbin value [CODESPLIT] @ Override public FSTClazzInfo readClass ( ) throws IOException , ClassNotFoundException { if ( lastDirectClass != null ) { FSTClazzInfo clInfo = conf . getCLInfoRegistry ( ) . getCLInfo ( lastDirectClass , conf ) ; lastDirectClass = null ; return clInfo ; } return null ; }


Input: will throw an FSTBufferTooSmallException if buffer is too small . [CODESPLIT] public int toByteArray ( Object obj , byte result [ ] , int resultOffset , int avaiableSize ) { output . resetForReUse ( ) ; try { output . writeObject ( obj ) ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } int written = output . getWritten ( ) ; if ( written > avaiableSize ) { throw FSTBufferTooSmallException . Instance ; } System . arraycopy ( output . getBuffer ( ) , 0 , result , resultOffset , written ) ; return written ; }


Input: len < 127 !!!!! [CODESPLIT] @ Override public String readStringAsc ( ) throws IOException { int len = readFInt ( ) ; if ( ascStringCache == null || ascStringCache . length ( ) < len ) ascStringCache = new HeapBytez ( new byte [ len ] ) ; ensureReadAhead ( len ) ; //        System.arraycopy(input.buf, input.pos, ascStringCache, 0, len); input . copyTo ( ascStringCache , 0 , pos , len ) ; pos += len ; return new String ( ascStringCache . getBase ( ) , 0 , 0 , len ) ; }


Input: assumes class header + len already read [CODESPLIT] @ Override public Object readFPrimitiveArray ( Object array , Class componentType , int len ) { // FIXME: if else chaining could be avoided if ( componentType == byte . class ) { ensureReadAhead ( len ) ; byte arr [ ] = ( byte [ ] ) array ; input . getArr ( pos , arr , 0 , len ) ; pos += len ; return arr ; } else if ( componentType == char . class ) { ensureReadAhead ( len * 2 ) ; char [ ] arr = ( char [ ] ) array ; input . getCharArr ( pos , arr , 0 , len ) ; pos += len * 2 ; return arr ; } else if ( componentType == short . class ) { ensureReadAhead ( len * 2 ) ; short [ ] arr = ( short [ ] ) array ; input . getShortArr ( pos , arr , 0 , len ) ; pos += len * 2 ; return arr ; } else if ( componentType == int . class ) { ensureReadAhead ( len * 4 ) ; int [ ] arr = ( int [ ] ) array ; input . getIntArr ( pos , arr , 0 , len ) ; pos += len * 4 ; return arr ; } else if ( componentType == float . class ) { ensureReadAhead ( len * 4 ) ; float [ ] arr = ( float [ ] ) array ; input . getFloatArr ( pos , arr , 0 , len ) ; pos += len * 4 ; return arr ; } else if ( componentType == double . class ) { ensureReadAhead ( len * 8 ) ; double [ ] arr = ( double [ ] ) array ; input . getDoubleArr ( pos , arr , 0 , len ) ; pos += len * 8 ; return arr ; } else if ( componentType == long . class ) { ensureReadAhead ( len * 8 ) ; long [ ] arr = ( long [ ] ) array ; input . getLongArr ( pos , arr , 0 , len ) ; pos += len * 8 ; return arr ; } else if ( componentType == boolean . class ) { ensureReadAhead ( len ) ; boolean [ ] arr = ( boolean [ ] ) array ; input . getBooleanArr ( pos , arr , 0 , len ) ; pos += len ; return arr ; } else { throw new RuntimeException ( "unexpected primitive type " + componentType . getName ( ) ) ; } }


Input: obsolete [CODESPLIT] public static String getPackage ( Class clazz ) { String s = clazz . getName ( ) ; int i = s . lastIndexOf ( ' ' ) ; if ( i >= 0 ) { s = s . substring ( i + 2 ) ; } i = s . lastIndexOf ( ' ' ) ; if ( i >= 0 ) { return s . substring ( 0 , i ) ; } return "" ; }


Input: hack to update underlying file in slices handed out to app [CODESPLIT] public void _setMMFData ( File file , FileChannel fileChannel , Cleaner cleaner ) { this . file = file ; this . fileChannel = fileChannel ; this . cleaner = cleaner ; }


Input: Returns the specificity of the specified class as defined above . [CODESPLIT] public static int getSpecificity ( final Class < ? > clazz ) { if ( clazz == null ) return 0 ; final LineageInfo lineageInfo = FSTClazzLineageInfo . getLineageInfo ( clazz ) ; return lineageInfo == null ? 0 : lineageInfo . specificity ; }


Input: Returns the lineage of the specified class ordered by specificity ( the class itself is at position 0 since it is most specific in its lineage ) . [CODESPLIT] public static Class < ? > [ ] getLineage ( final Class < ? > clazz ) { final LineageInfo lineageInfo = getLineageInfo ( clazz ) ; return lineageInfo == null ? EMPTY_CLASS_ARRAY : lineageInfo . lineage . toArray ( new Class < ? > [ lineageInfo . lineage . size ( ) ] ) ; }


Input: PRIVILEGED method . You gotta know what your doing here .. [CODESPLIT] public void resizeStore ( long required , long maxgrowbytes ) { if ( mappedFile == null ) throw new RuntimeException ( "store is full. Required: " + required ) ; if ( required <= memory . length ( ) ) return ; mutationCount ++ ; System . out . println ( "resizing underlying " + mappedFile + " to " + required + " numElem:" + numElem ) ; long tim = System . currentTimeMillis ( ) ; ( ( MMFBytez ) memory ) . freeAndClose ( ) ; memory = null ; try { File mf = new File ( mappedFile ) ; FileOutputStream f = new FileOutputStream ( mf , true ) ; long len = mf . length ( ) ; required = required + Math . min ( required , maxgrowbytes ) ; byte [ ] toWrite = new byte [ 1000 ] ; long max = ( required - len ) / 1000 ; for ( long i = 0 ; i < max + 2 ; i ++ ) { f . write ( toWrite ) ; } f . flush ( ) ; f . close ( ) ; resetMem ( mappedFile , mf . length ( ) ) ; System . out . println ( "resizing done in " + ( System . currentTimeMillis ( ) - tim ) + " numElemAfter:" + numElem ) ; } catch ( FileNotFoundException e ) { e . printStackTrace ( ) ; } catch ( IOException e ) { e . printStackTrace ( ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; } }


Input: get an entry . the returned ByteSource must be processed immediately as it will be reused internally on next get Warning : Concurrent Modification ( e . g . add remove elements during iteration ) is NOT SUPPORTED and NOT CHECKED . Collect keys to change inside iteration and perform changes after iteration is finished . [CODESPLIT] public BytezByteSource getBinary ( ByteSource key ) { checkThread ( ) ; if ( key . length ( ) != keyLen ) throw new RuntimeException ( "key must have length " + keyLen ) ; long aLong = index . get ( key ) ; if ( aLong == 0 ) { return null ; } long off = aLong ; int len = getContentLenFromHeader ( off ) ; off += getHeaderLen ( ) ; tmpValueBytez . setLen ( len ) ; tmpValueBytez . setOff ( off ) ; return tmpValueBytez ; }


Input: remove the key from the binary map [CODESPLIT] public void removeBinary ( ByteSource key ) { checkThread ( ) ; if ( key . length ( ) != keyLen ) throw new RuntimeException ( "key must have length " + keyLen ) ; mutationCount ++ ; long rem = index . get ( key ) ; if ( rem != 0 ) { index . remove ( key ) ; decElems ( ) ; removeEntry ( rem ) ; } }


Input: } [CODESPLIT] public void writeFShortArr ( short [ ] arr , int off , int len ) throws IOException { buffout . ensureFree ( len * 3 ) ; for ( int i = off ; i < off + len ; i ++ ) { short c = arr [ i ] ; if ( c < 255 && c >= 0 ) { buffout . buf [ buffout . pos ++ ] = ( byte ) c ; } else { buffout . buf [ buffout . pos ] = ( byte ) 255 ; buffout . buf [ buffout . pos + 1 ] = ( byte ) ( c >>> 0 ) ; buffout . buf [ buffout . pos + 2 ] = ( byte ) ( c >>> 8 ) ; buffout . pos += 3 ; } } }


Input: uncompressed version [CODESPLIT] public void writeFIntArr ( int [ ] arr , int off , int len ) throws IOException { int byteLen = arr . length * 4 ; buffout . ensureFree ( byteLen ) ; byte buf [ ] = buffout . buf ; int count = buffout . pos ; int max = off + len ; for ( int i = off ; i < max ; i ++ ) { long anInt = arr [ i ] ; buf [ count ] = ( byte ) ( anInt >>> 0 ) ; buf [ count + 1 ] = ( byte ) ( anInt >>> 8 ) ; buf [ count + 2 ] = ( byte ) ( anInt >>> 16 ) ; buf [ count + 3 ] = ( byte ) ( anInt >>> 24 ) ; count += 4 ; } buffout . pos += byteLen ; }


Input: compressed version [CODESPLIT] public void _writeFIntArr ( int v [ ] , int off , int len ) throws IOException { final int free = 5 * len ; buffout . ensureFree ( free ) ; final byte [ ] buf = buffout . buf ; int count = buffout . pos ; for ( int i = off ; i < off + len ; i ++ ) { final int anInt = v [ i ] ; if ( anInt > - 127 && anInt <= 127 ) { buffout . buf [ count ++ ] = ( byte ) anInt ; } else if ( anInt >= Short . MIN_VALUE && anInt <= Short . MAX_VALUE ) { buf [ count ++ ] = - 128 ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 0 ) & 0xFF ) ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 8 ) & 0xFF ) ; } else { buf [ count ++ ] = - 127 ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 0 ) & 0xFF ) ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 8 ) & 0xFF ) ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 16 ) & 0xFF ) ; buf [ count ++ ] = ( byte ) ( ( anInt >>> 24 ) & 0xFF ) ; } } buffout . pos = count ; }


Input: does not write length just plain bytes [CODESPLIT] public void writeRawBytes ( byte [ ] array , int start , int length ) throws IOException { buffout . ensureFree ( length ) ; System . arraycopy ( array , start , buffout . buf , buffout . pos , length ) ; buffout . pos += length ; }


Input: length < 127 !!!!! [CODESPLIT] void writeStringAsc ( String name ) throws IOException { int len = name . length ( ) ; if ( len >= 127 ) { throw new RuntimeException ( "Ascii String too long" ) ; } writeFByte ( ( byte ) len ) ; buffout . ensureFree ( len ) ; if ( ascStringCache == null || ascStringCache . length < len ) ascStringCache = new byte [ len ] ; name . getBytes ( 0 , len , ascStringCache , 0 ) ; writeRawBytes ( ascStringCache , 0 , len ) ; }


Input: used to write uncompressed int ( guaranteed length = 4 ) at a ( eventually recent ) position [CODESPLIT] @ Override public void writeInt32At ( int position , int v ) { buffout . buf [ position ] = ( byte ) ( v >>> 0 ) ; buffout . buf [ position + 1 ] = ( byte ) ( v >>> 8 ) ; buffout . buf [ position + 2 ] = ( byte ) ( v >>> 16 ) ; buffout . buf [ position + 3 ] = ( byte ) ( v >>> 24 ) ; }


Input: if output stream is null just encode into a byte array [CODESPLIT] @ Override public void setOutstream ( OutputStream outstream ) { if ( buffout == null ) { // try reuse buffout = ( FSTOutputStream ) conf . getCachedObject ( FSTOutputStream . class ) ; if ( buffout == null ) // if fail, alloc buffout = new FSTOutputStream ( 1000 , outstream ) ; else buffout . reset ( ) ; // reset resued fstoutput } if ( outstream == null ) buffout . setOutstream ( buffout ) ; else buffout . setOutstream ( outstream ) ; }


Input: allocates a StructAccessor ( pointer ) matching the struct data expected in the byte array at given position . The resulting pointer object is not volatile ( not a cached instance ) [CODESPLIT] public FSTStruct createStructWrapper ( Bytez b , long index ) { int clzId = b . getInt ( index + 4 ) ; return createStructPointer ( b , index , clzId ) ; }


Input: allocates a StructAccessor ( pointer ) matching the struct data expected in the byte array at given position with given classId . The resulting pointer object is not volatile ( not a cached instance ) . The class id should match the Struct stored in the byte array . ( classId must be the correct struct or a superclass of it ) [CODESPLIT] public FSTStruct createStructPointer ( Bytez b , long index , int clzId ) { //        synchronized (this) // FIXME FIXME FIXME: contention point // desynced expecting class registering happens on startup { Class clazz = mIntToClz . get ( clzId ) ; if ( clazz == null ) throw new RuntimeException ( "unregistered class " + clzId ) ; try { return ( FSTStruct ) createWrapper ( clazz , b , index ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } }


Input: create a json conf with given attributes . Note that shared refs = true for jason might be not as stable as for binary encodings as fst relies on stream positions to identify objects within a given input so any inbetween formatting will break proper reference resolution . [CODESPLIT] public static FSTConfiguration createJsonConfiguration ( boolean prettyPrint , boolean shareReferences ) { if ( shareReferences && prettyPrint ) { throw new RuntimeException ( "unsupported flag combination" ) ; } return createJsonConfiguration ( prettyPrint , shareReferences , null ) ; }


Input: debug only very slow ( creates config with each call ) . Creates new conf so custom serializers are ignored . [CODESPLIT] public static void prettyPrintJson ( Object o ) { FSTConfiguration conf = constructJsonConf ( true , true , null ) ; System . out . println ( conf . asJsonString ( o ) ) ; }


Input: register a custom serializer for a given class or the class and all of its subclasses . Serializers must be configured identical on read / write side and should be set before actually making use of the Configuration . [CODESPLIT] public void registerSerializer ( Class clazz , FSTObjectSerializer ser , boolean alsoForAllSubclasses ) { serializationInfoRegistry . getSerializerRegistry ( ) . putSerializer ( clazz , ser , alsoForAllSubclasses ) ; }


Input: special configuration used internally for struct emulation [CODESPLIT] public static FSTConfiguration createStructConfiguration ( ) { FSTConfiguration conf = new FSTConfiguration ( null ) ; conf . setStructMode ( true ) ; return conf ; }


Input: reuse heavy weight objects . If a FSTStream is closed objects are returned and can be reused by new stream instances . the objects are held in soft references so there should be no memory issues . FIXME : point of contention ! [CODESPLIT] public void returnObject ( Object cached ) { try { while ( ! cacheLock . compareAndSet ( false , true ) ) { // empty } List < SoftReference > li = cachedObjects . get ( cached . getClass ( ) ) ; if ( li == null ) { li = new ArrayList < SoftReference > ( ) ; cachedObjects . put ( cached . getClass ( ) , li ) ; } if ( li . size ( ) < 5 ) li . add ( new SoftReference ( cached ) ) ; } finally { cacheLock . set ( false ) ; } }


Input: for optimization purposes do not use to benchmark processing time or in a regular program as this methods creates a temporary binaryoutputstream and serializes the object in order to measure the size . [CODESPLIT] public int calcObjectSizeBytesNotAUtility ( Object obj ) throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream ( 10000 ) ; FSTObjectOutput ou = new FSTObjectOutput ( bout , this ) ; ou . writeObject ( obj , obj . getClass ( ) ) ; ou . close ( ) ; return bout . toByteArray ( ) . length ; }


Input: clear cached softref s and ThreadLocal . [CODESPLIT] public void clearCaches ( ) { try { FSTInputStream . cachedBuffer . set ( null ) ; while ( ! cacheLock . compareAndSet ( false , true ) ) { // empty } cachedObjects . clear ( ) ; } finally { cacheLock . set ( false ) ; } }


Input: utility for thread safety and reuse . Do not close the resulting stream . However you should close the given InputStream in [CODESPLIT] public FSTObjectInput getObjectInput ( InputStream in ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuse ( in ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: take the given array as input . the array is NOT copied . [CODESPLIT] public FSTObjectInput getObjectInput ( byte arr [ ] , int len ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuseUseArray ( arr , len ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: take the given array and copy it to input . the array IS copied [CODESPLIT] public FSTObjectInput getObjectInputCopyFrom ( byte arr [ ] , int off , int len ) { FSTObjectInput fstObjectInput = getIn ( ) ; try { fstObjectInput . resetForReuseCopyArray ( arr , off , len ) ; return fstObjectInput ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: utility for thread safety and reuse . Do not close the resulting stream . However you should close the given OutputStream out [CODESPLIT] public FSTObjectOutput getObjectOutput ( OutputStream out ) { FSTObjectOutput fstObjectOutput = getOut ( ) ; fstObjectOutput . resetForReUse ( out ) ; return fstObjectOutput ; }


Input: init right after creation of configuration not during operation as it is not threadsafe regarding mutation currently only for minbin serialization [CODESPLIT] public FSTConfiguration registerCrossPlatformClassMapping ( String [ ] [ ] keysAndVals ) { for ( int i = 0 ; i < keysAndVals . length ; i ++ ) { String [ ] keysAndVal = keysAndVals [ i ] ; registerCrossPlatformClassMapping ( keysAndVal [ 0 ] , keysAndVal [ 1 ] ) ; } return this ; }


Input: shorthand for registerCrossPlatformClassMapping ( _ _ ) [CODESPLIT] public FSTConfiguration cpMap ( String shortName , Class clz ) { return registerCrossPlatformClassMapping ( shortName , clz . getName ( ) ) ; }


Input: get cross platform symbolic class identifier [CODESPLIT] public String getCPNameForClass ( Class cl ) { String res = minbinNamesReverse . get ( cl . getName ( ) ) ; if ( res == null ) { if ( cl . isAnonymousClass ( ) ) { return getCPNameForClass ( cl . getSuperclass ( ) ) ; } return cl . getName ( ) ; } return res ; }


Input: convenience [CODESPLIT] public Object asObject ( byte b [ ] ) { try { return getObjectInput ( b ) . readObject ( ) ; } catch ( Exception e ) { System . out . println ( "unable to decode:" + new String ( b , 0 , 0 , Math . min ( b . length , 100 ) ) ) ; try { String debug = new String ( b , "UTF-8" ) ; } catch ( UnsupportedEncodingException e1 ) { // } try { getObjectInput ( b ) . readObject ( ) ; } catch ( Exception e1 ) { // debug hook } FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: convenience . ( object must be serializable ) [CODESPLIT] public byte [ ] asByteArray ( Object object ) { FSTObjectOutput objectOutput = getObjectOutput ( ) ; try { objectOutput . writeObject ( object ) ; return objectOutput . getCopyOfWrittenBuffer ( ) ; } catch ( IOException e ) { try { //                FSTConfiguration.prettyPrintJson(object); endless cycle ! } catch ( Exception ee ) { // } FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: Warning : avoids allocation + copying . The returned byteArray is a direct pointer to underlying buffer . the int length [] is expected to have at least on element . The buffer can be larger than written data therefore length [ 0 ] will contain written length . [CODESPLIT] public byte [ ] asSharedByteArray ( Object object , int length [ ] ) { FSTObjectOutput objectOutput = getObjectOutput ( ) ; try { objectOutput . writeObject ( object ) ; length [ 0 ] = objectOutput . getWritten ( ) ; return objectOutput . getBuffer ( ) ; } catch ( IOException e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } return null ; }


Input: utility / debug method . Use asByteArray for programmatic use as the byte array will already by UTF - 8 and ready to be sent on network . [CODESPLIT] public String asJsonString ( Object o ) { if ( getCoderSpecific ( ) instanceof JsonFactory == false ) { return "can be called on JsonConfiguration only" ; } else { return new String ( asByteArray ( o ) , StandardCharsets . UTF_8 ) ; } }


Input: helper to write series of objects to streams / files > Integer . MAX_VALUE . it - serializes the object - writes the length of the serialized object to the stream - the writes the serialized object data [CODESPLIT] public void encodeToStream ( OutputStream out , Object toSerialize ) throws IOException { FSTObjectOutput objectOutput = getObjectOutput ( ) ; // could also do new with minor perf impact objectOutput . writeObject ( toSerialize ) ; int written = objectOutput . getWritten ( ) ; out . write ( ( written >>> 0 ) & 0xFF ) ; out . write ( ( written >>> 8 ) & 0xFF ) ; out . write ( ( written >>> 16 ) & 0xFF ) ; out . write ( ( written >>> 24 ) & 0xFF ) ; // copy internal buffer to bufferedoutput out . write ( objectOutput . getBuffer ( ) , 0 , written ) ; objectOutput . flush ( ) ; }


Input: @see encodeToStream [CODESPLIT] public Object decodeFromStream ( InputStream in ) throws Exception { int read = in . read ( ) ; if ( read < 0 ) throw new EOFException ( "stream is closed" ) ; int ch1 = ( read + 256 ) & 0xff ; int ch2 = ( in . read ( ) + 256 ) & 0xff ; int ch3 = ( in . read ( ) + 256 ) & 0xff ; int ch4 = ( in . read ( ) + 256 ) & 0xff ; int len = ( ch4 << 24 ) + ( ch3 << 16 ) + ( ch2 << 8 ) + ( ch1 << 0 ) ; if ( len <= 0 ) throw new EOFException ( "stream is corrupted" ) ; byte buffer [ ] = new byte [ len ] ; // this could be reused ! while ( len > 0 ) { len -= in . read ( buffer , buffer . length - len , len ) ; } return getObjectInput ( buffer ) . readObject ( ) ; }


Input: sideeffecting : if no ser is found next lookup will return null immediate [CODESPLIT] public FSTObjectSerializer getSer ( ) { if ( ser == null ) { if ( clazz == null ) { return null ; } ser = getSerNoStore ( ) ; if ( ser == null ) { ser = FSTSerializerRegistry . NULL ; } } if ( ser == FSTSerializerRegistry . NULL ) { return null ; } return ser ; }


Input: write an int type with header [CODESPLIT] public void writeInt ( byte type , long data ) { if ( ! MinBin . isPrimitive ( type ) || MinBin . isArray ( type ) ) throw new RuntimeException ( "illegal type code" ) ; writeOut ( type ) ; writeRawInt ( type , data ) ; }


Input: encode int without header tag [CODESPLIT] protected void writeRawInt ( byte type , long data ) { int numBytes = MinBin . extractNumBytes ( type ) ; for ( int i = 0 ; i < numBytes ; i ++ ) { writeOut ( ( byte ) ( data & 0xff ) ) ; data = data >>> 8 ; } }


Input: encode int using only as much bytes as needed to represent it [CODESPLIT] public void writeIntPacked ( long data ) { if ( data <= Byte . MAX_VALUE && data >= Byte . MIN_VALUE ) writeInt ( MinBin . INT_8 , data ) ; else if ( data <= Short . MAX_VALUE && data >= Short . MIN_VALUE ) writeInt ( MinBin . INT_16 , data ) ; else if ( data <= Integer . MAX_VALUE && data >= Integer . MIN_VALUE ) writeInt ( MinBin . INT_32 , data ) ; else if ( data <= Long . MAX_VALUE && data >= Long . MIN_VALUE ) writeInt ( MinBin . INT_64 , data ) ; }


Input: write primitive array + header . no floating point or object array allowed . Just int based types [CODESPLIT] public void writeArray ( Object primitiveArray , int start , int len ) { byte type = MinBin . ARRAY_MASK ; Class < ? > componentType = primitiveArray . getClass ( ) . getComponentType ( ) ; if ( componentType == boolean . class ) type |= MinBin . INT_8 ; else if ( componentType == byte . class ) type |= MinBin . INT_8 ; else if ( componentType == short . class ) type |= MinBin . INT_16 ; else if ( componentType == char . class ) type |= MinBin . INT_16 | MinBin . UNSIGN_MASK ; else if ( componentType == int . class ) type |= MinBin . INT_32 ; else if ( componentType == long . class ) type |= MinBin . INT_64 ; else throw new RuntimeException ( "unsupported type " + componentType . getName ( ) ) ; writeOut ( type ) ; writeIntPacked ( len ) ; switch ( type ) { case MinBin . INT_8 | MinBin . ARRAY_MASK : { if ( componentType == boolean . class ) { boolean [ ] arr = ( boolean [ ] ) primitiveArray ; for ( int i = start ; i < start + len ; i ++ ) { writeRawInt ( type , arr [ i ] ? 1 : 0 ) ; } } else { byte [ ] arr = ( byte [ ] ) primitiveArray ; for ( int i = start ; i < start + len ; i ++ ) { writeRawInt ( type , arr [ i ] ) ; } } } break ; case MinBin . CHAR | MinBin . ARRAY_MASK : { char [ ] charArr = ( char [ ] ) primitiveArray ; for ( int i = start ; i < start + len ; i ++ ) { writeRawInt ( type , charArr [ i ] ) ; } } break ; case MinBin . INT_32 | MinBin . ARRAY_MASK : { int [ ] arr = ( int [ ] ) primitiveArray ; for ( int i = start ; i < start + len ; i ++ ) { writeRawInt ( type , arr [ i ] ) ; } } break ; case MinBin . INT_64 | MinBin . ARRAY_MASK : { long [ ] arr = ( long [ ] ) primitiveArray ; for ( int i = start ; i < start + len ; i ++ ) { writeRawInt ( type , arr [ i ] ) ; } } break ; default : { for ( int i = start ; i < start + len ; i ++ ) { if ( componentType == boolean . class ) writeRawInt ( type , Array . getBoolean ( primitiveArray , i ) ? 1 : 0 ) ; else writeRawInt ( type , Array . getLong ( primitiveArray , i ) ) ; } } } }


Input: allow write through to underlying byte for performance reasons [CODESPLIT] public void writeRaw ( byte [ ] bufferedName , int i , int length ) { if ( pos + length >= bytez . length - 1 ) { resize ( ) ; } System . arraycopy ( bufferedName , i , bytez , pos , length ) ; pos += length ; }


Input: read into preallocated array allows to write to different type ( e . g . boolean [] from byte [] ) [CODESPLIT] public Object readArrayRaw ( byte type , int len , Object resultingArray ) { Class componentType = resultingArray . getClass ( ) . getComponentType ( ) ; if ( componentType == byte . class ) { byte [ ] barr = ( byte [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { barr [ i ] = ( byte ) readRawInt ( type ) ; } } else if ( componentType == short . class ) { short [ ] sArr = ( short [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { sArr [ i ] = ( short ) readRawInt ( type ) ; } } else if ( componentType == char . class ) { char [ ] cArr = ( char [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { cArr [ i ] = ( char ) readRawInt ( type ) ; } } else if ( componentType == int . class ) { int [ ] iArr = ( int [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { iArr [ i ] = ( int ) readRawInt ( type ) ; } } else if ( componentType == long . class ) { long [ ] lArr = ( long [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { lArr [ i ] = readRawInt ( type ) ; } } else if ( componentType == boolean . class ) { boolean [ ] boolArr = ( boolean [ ] ) resultingArray ; for ( int i = 0 ; i < len ; i ++ ) { boolArr [ i ] = readRawInt ( MinBin . INT_8 ) != 0 ; } } else throw new RuntimeException ( "unsupported array type " + resultingArray . getClass ( ) . getName ( ) ) ; return resultingArray ; }


Input: /////////////////////////////////////////////////// [CODESPLIT] public void writeObject ( Object obj , Class ... possibles ) throws IOException { if ( isCrossPlatform ) { writeObjectInternal ( obj , null ) ; // not supported cross platform return ; } if ( possibles != null && possibles . length > 1 ) { for ( int i = 0 ; i < possibles . length ; i ++ ) { Class possible = possibles [ i ] ; getCodec ( ) . registerClass ( possible ) ; } } writeObjectInternal ( obj , null , possibles ) ; }


Input: avoid creation of dummy ref [CODESPLIT] protected FSTClazzInfo . FSTFieldInfo getCachedFI ( Class ... possibles ) { if ( refs == null ) { refs = refsLocal . get ( ) ; } if ( curDepth >= refs . length ) { return new FSTClazzInfo . FSTFieldInfo ( possibles , null , true ) ; } else { FSTClazzInfo . FSTFieldInfo inf = refs [ curDepth ] ; if ( inf == null ) { inf = new FSTClazzInfo . FSTFieldInfo ( possibles , null , true ) ; refs [ curDepth ] = inf ; return inf ; } inf . setPossibleClasses ( possibles ) ; return inf ; } }


Input: hook for debugging profiling . register a FSTSerialisationListener to use [CODESPLIT] protected void objectWillBeWritten ( Object obj , int streamPosition ) { if ( listener != null ) { listener . objectWillBeWritten ( obj , streamPosition ) ; } }


Input: hook for debugging profiling . empty impl you need to subclass to make use of this hook [CODESPLIT] protected void objectHasBeenWritten ( Object obj , int oldStreamPosition , int streamPosition ) { if ( listener != null ) { listener . objectHasBeenWritten ( obj , oldStreamPosition , streamPosition ) ; } }


Input: splitting this slows down ... [CODESPLIT] protected FSTClazzInfo writeObjectWithContext ( FSTClazzInfo . FSTFieldInfo referencee , Object toWrite , FSTClazzInfo ci ) throws IOException { int startPosition = 0 ; try { if ( toWrite == null ) { getCodec ( ) . writeTag ( NULL , null , 0 , toWrite , this ) ; return null ; } startPosition = getCodec ( ) . getWritten ( ) ; objectWillBeWritten ( toWrite , startPosition ) ; final Class clazz = toWrite . getClass ( ) ; if ( clazz == String . class ) { String [ ] oneOf = referencee . getOneOf ( ) ; if ( oneOf != null ) { for ( int i = 0 ; i < oneOf . length ; i ++ ) { String s = oneOf [ i ] ; if ( s . equals ( toWrite ) ) { getCodec ( ) . writeTag ( ONE_OF , oneOf , i , toWrite , this ) ; getCodec ( ) . writeFByte ( i ) ; return null ; } } } // shortpath if ( ! dontShare && writeHandleIfApplicable ( toWrite , stringInfo ) ) return stringInfo ; getCodec ( ) . writeTag ( STRING , toWrite , 0 , toWrite , this ) ; getCodec ( ) . writeStringUTF ( ( String ) toWrite ) ; return null ; } else if ( clazz == Integer . class ) { getCodec ( ) . writeTag ( BIG_INT , null , 0 , toWrite , this ) ; getCodec ( ) . writeFInt ( ( ( Integer ) toWrite ) . intValue ( ) ) ; return null ; } else if ( clazz == Long . class ) { getCodec ( ) . writeTag ( BIG_LONG , null , 0 , toWrite , this ) ; getCodec ( ) . writeFLong ( ( ( Long ) toWrite ) . longValue ( ) ) ; return null ; } else if ( clazz == Boolean . class ) { getCodec ( ) . writeTag ( ( ( Boolean ) toWrite ) . booleanValue ( ) ? BIG_BOOLEAN_TRUE : BIG_BOOLEAN_FALSE , null , 0 , toWrite , this ) ; return null ; } else if ( ( referencee . getType ( ) != null && referencee . getType ( ) . isEnum ( ) ) || toWrite instanceof Enum ) { return writeEnum ( referencee , toWrite ) ; } FSTClazzInfo serializationInfo = ci == null ? getFstClazzInfo ( referencee , clazz ) : ci ; // check for identical / equal objects FSTObjectSerializer ser = serializationInfo . getSer ( ) ; if ( ! dontShare && ! referencee . isFlat ( ) && ! serializationInfo . isFlat ( ) && ( ser == null || ! ser . alwaysCopy ( ) ) ) { if ( writeHandleIfApplicable ( toWrite , serializationInfo ) ) return serializationInfo ; } if ( clazz . isArray ( ) ) { if ( getCodec ( ) . writeTag ( ARRAY , toWrite , 0 , toWrite , this ) ) return serializationInfo ; // some codecs handle primitive arrays like an primitive type writeArray ( referencee , toWrite ) ; getCodec ( ) . writeArrayEnd ( ) ; } else if ( ser == null ) { // default write object wihtout custom serializer // handle write replace //if ( ! dontShare ) GIT ISSUE 80 FSTClazzInfo originalInfo = serializationInfo ; { if ( serializationInfo . getWriteReplaceMethod ( ) != null ) { Object replaced = null ; try { replaced = serializationInfo . getWriteReplaceMethod ( ) . invoke ( toWrite ) ; } catch ( Exception e ) { FSTUtil . < RuntimeException > rethrow ( e ) ; } if ( replaced != toWrite ) { toWrite = replaced ; serializationInfo = getClassInfoRegistry ( ) . getCLInfo ( toWrite . getClass ( ) , conf ) ; // fixme: update object map ? } } // clazz uses some JDK special stuff (frequently slow) if ( serializationInfo . useCompatibleMode ( ) && ! serializationInfo . isExternalizable ( ) ) { writeObjectCompatible ( referencee , toWrite , serializationInfo ) ; return originalInfo ; } } if ( ! writeObjectHeader ( serializationInfo , referencee , toWrite ) ) { // skip in case codec can write object as primitive ser = serializationInfo . getSer ( ) ; if ( ser == null ) { defaultWriteObject ( toWrite , serializationInfo ) ; if ( serializationInfo . isExternalizable ( ) ) getCodec ( ) . externalEnd ( serializationInfo ) ; } else { // handle edge case: there is a serializer registered for replaced class // copied from below :( int pos = getCodec ( ) . getWritten ( ) ; // write object depending on type (custom, externalizable, serializable/java, default) ser . writeObject ( this , toWrite , serializationInfo , referencee , pos ) ; getCodec ( ) . externalEnd ( serializationInfo ) ; } } return originalInfo ; } else { // object has custom serializer // Object header (nothing written till here) if ( ! writeObjectHeader ( serializationInfo , referencee , toWrite ) ) { // skip in case code can write object as primitive int pos = getCodec ( ) . getWritten ( ) ; // write object depending on type (custom, externalizable, serializable/java, default) ser . writeObject ( this , toWrite , serializationInfo , referencee , pos ) ; getCodec ( ) . externalEnd ( serializationInfo ) ; } } return serializationInfo ; } finally { objectHasBeenWritten ( toWrite , startPosition , getCodec ( ) . getWritten ( ) ) ; } }