All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.bugvm.apple.corefoundation.CFData Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2013-2015 RoboVM AB
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.bugvm.apple.corefoundation;

/**/
import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.dispatch.*;
import com.bugvm.apple.coreservices.*;
import com.bugvm.apple.coremedia.*;
import com.bugvm.apple.uikit.*;
import com.bugvm.apple.coretext.*;
/**/

/**/
/**/
/**/@Library("CoreFoundation")/**/
/**/public/**/ class /**/CFData/**/ 
    extends /**/CFPropertyList/**/ 
    /**//**/ {

    /**/public static class CFDataPtr extends Ptr {}/**/
    
    private static final int EFFECTIVE_DIRECT_ADDRESS_OFFSET;

    static {
        try {
            java.lang.reflect.Field f1 = Buffer.class.getDeclaredField("effectiveDirectAddress");
            if (f1.getType() != long.class) {
                throw new Error("java.nio.Buffer.effectiveDirectAddress should be a long");
            }
            EFFECTIVE_DIRECT_ADDRESS_OFFSET = VM.getInstanceFieldOffset(VM.getFieldAddress(f1));
        } catch (NoSuchFieldException e) {
            throw new Error(e);
        }
    }
    
    static long getEffectiveAddress(ByteBuffer bytes) {
        if (!bytes.isDirect()) {
            throw new IllegalArgumentException("Direct ByteBuffer expected");
        }
        return VM.getLong(VM.getObjectAddress(bytes) + EFFECTIVE_DIRECT_ADDRESS_OFFSET);
    }
    /**/static { Bro.bind(CFData.class); }/**/
    /**//**/
    /**/
    protected CFData() {}
    /**/
    /**//**/
    /**//**/
    public static CFData create(byte[] bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes");
        }
        return create((CFAllocator)null, VM.getArrayValuesAddress(bytes), bytes.length);
    }
    public static CFData create(ByteBuffer bytes) {
        if (bytes == null) {
            throw new NullPointerException("bytes");
        }
        long handle = getEffectiveAddress(bytes) + bytes.position();
        CFData result = create(null, handle, bytes.remaining(), null);
        return result;
    }
    public static CFData createCopy(CFData theData) {
        return createCopy(null, theData);
    }
    public ByteBuffer asByteBuffer() {
        return VM.newDirectByteBuffer(getBytePtr(), getLength());
    }

    public byte[] getBytes() {
        int length = (int) getLength();
        byte[] bytes = new byte[length];
        getBytes(new CFRange(0, length), VM.getArrayValuesAddress(bytes));
        return bytes;
    }
    /**/
    @Bridge(symbol="CFDataGetTypeID", optional=true)
    public static native @MachineSizedUInt long getClassTypeID();
    @Bridge(symbol="CFDataCreate", optional=true)
    private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFData create(CFAllocator allocator, @Pointer long bytes, @MachineSizedSInt long length);
    @Bridge(symbol="CFDataCreateWithBytesNoCopy", optional=true)
    private static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFData create(CFAllocator allocator, @Pointer long bytes, @MachineSizedSInt long length, CFAllocator bytesDeallocator);
    @Bridge(symbol="CFDataCreateCopy", optional=true)
    public static native @com.bugvm.rt.bro.annotation.Marshaler(CFType.NoRetainMarshaler.class) CFData createCopy(CFAllocator allocator, CFData theData);
    @Bridge(symbol="CFDataGetLength", optional=true)
    public native @MachineSizedSInt long getLength();
    @Bridge(symbol="CFDataGetBytePtr", optional=true)
    protected native @Pointer long getBytePtr();
    @Bridge(symbol="CFDataGetBytes", optional=true)
    protected native void getBytes(@ByVal CFRange range, @Pointer long buffer);
    /**
     * @since Available in iOS 4.0 and later.
     */
    @Bridge(symbol="CFDataFind", optional=true)
    public native @ByVal CFRange find(CFData dataToFind, @ByVal CFRange searchRange, CFDataSearchFlags compareOptions);
    /**/
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy