Bytebuffer byteBuffer = Bytebuffer.NEW();

Asked

Viewed 85 times

1

I have a problem with Bytebuffer byteBuffer = Bytebuffer.NEW();

I can’t understand why I don’t have access to it. NEW, it simply doesn’t exist, I don’t think and I don’t find it... I need it to create the logic of a PDF to JPG conversion... Does anyone have an idea how to find it??? NOTE: It is for JAVA ANDROID.

    byte[] bytes;
    FileInputStream is = new FileInputStream(file);
    long length = file.length();
    bytes = new byte[(int) length];
    int offset = 0;
    int numRead = 0;
    while (offset < bytes.length
            && (numRead = is.read(bytes, offset, bytes.length
            - offset)) >= 0) {
        offset += numRead;
    }

    ByteBuffer buffer = ByteBuffer.NEW(bytes);
    String data = Base64.encodeToString(bytes, Base64.DEFAULT);
    PDFFile pdf_file = new PDFFile(buffer);
    PDFPage page = pdf_file.getPage(1);

I found this example on Google, but I can’t remember where (I lost the link)...

  • I can find no method NEW in documentation, in fact it is strange a method with capitalized name (in Java, usually only use everything in upper case to denote constants). Where do you know this method from, do you have any reference you can indicate? Anyway, see if the method allocate or allocateDirect don’t suit you, or maybe the wrap if you already have an array of bytes and want to create a buffer from it.

  • Hello friend! I edited my question with the code I doubt, it is to take a page from a PDF and convert to JPG

  • 1

    In that case, most likely what you want is the wrap. Maybe the NEW refers to some fairly old version of the API, I don’t know... Try: ByteBuffer buffer = ByteBuffer.wrap(bytes);

  • Okay, I’ll take the test and pass the feedback!

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.