簡體   English   中英

MappedByteBuffer(在Android Studio中)構造函數已損壞(超級構造函數已損壞)

[英]MappedByteBuffer(in Android Studio) constructor is broken(super constructor broken)

我有一個字節數組,它必須轉換為 MappedByteBuffer。

但是當我嘗試創建 MappedByteBuffer 時,發生錯誤。

error: cannot find symbol method MappedByteBuffer(int,int,int,int,byte[],int)

映射字節緩沖區.java

package java.nio;

import java.io.FileDescriptor;
import sun.misc.Unsafe;

public abstract class MappedByteBuffer
    extends ByteBuffer
{

   ...

// Android-added: Additional constructor for use by Android's DirectByteBuffer.
    MappedByteBuffer(int mark, int pos, int lim, int cap, byte[] buf, int offset) {
        super(mark, pos, lim, cap, buf, offset);  // <- when I hover mouse here, ByteBuffer() in ByteBuffer cannot be applied to message appears with a red underline.
        this.fd = null;
    }

   ...

}

字節緩沖區.java

package java.nio;
import libcore.io.Memory;
import dalvik.annotation.codegen.CovariantReturnType;

public abstract class ByteBuffer
    extends Buffer
    implements Comparable<ByteBuffer>
{

    // These fields are declared here rather than in Heap-X-Buffer in order to
    // reduce the number of virtual method invocations needed to access these
    // values, which is especially costly when coding small buffers.
    //
    final byte[] hb;                  // Non-null only for heap buffers
    final int offset;
    boolean isReadOnly;                 // Valid only for heap buffers

    // Creates a new buffer with the given mark, position, limit, capacity,
    // backing array, and array offset
    //
    ByteBuffer(int mark, int pos, int lim, int cap,   // package-private
                 byte[] hb, int offset)
    {
        // Android-added: elementSizeShift parameter (log2 of element size).
        super(mark, pos, lim, cap, 0 /* elementSizeShift */);
        this.hb = hb;
        this.offset = offset;
    }

    ...

}

我覺得奇怪的是,當在 MappedByteBuffer.java 中轉到extends ByteBuffer定義時,它顯示的是 ByteBuffer.annotated.java,而不是 ByteBuffer.java

ByteBuffer.annotated.java


// -- This file was mechanically generated: Do not edit! -- //


package java.nio;


@SuppressWarnings({"unchecked", "deprecation", "all"})
public abstract class ByteBuffer extends java.nio.Buffer implements java.lang.Comparable<java.nio.ByteBuffer> {

ByteBuffer(int mark, int pos, int lim, int cap) { super(0, 0, 0, 0, 0); throw new RuntimeException("Stub!"); }

我不知道 {classname}.annotated.java 是做什么的,所以它可能不是錯誤,但我粘貼了,因為我認為它很奇怪。

那么如何從字節數組創建 MappedByteBuffer 呢? 只有 1 個構造函數,但它壞了。

只有 1 個構造函數,但它壞了

該構造函數不是公共的(它是包私有的),因此您不能調用它。

那么如何從字節數組創建 MappedByteBuffer 呢?

你不能,除非先將它寫入文件。 文檔

直接字節緩沖區,其內容是文件的內存映射區域。

如果確實需要專門創建MappedByteBuffer而不僅僅是從字節數組創建ByteBuffer ,則需要將其寫入文件並使用FileChannel.map 如果你只需要一個ByteBuffer ,你可以使用ByteBuffer.wrap

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM