Search in sources :

Example 1 with Chunk

use of org.elixir_lang.beam.chunk.Chunk in project intellij-elixir by KronicDeth.

the class Beam method from.

/*
     * Static Methods
     */
@Nullable
public static Beam from(@NotNull DataInputStream dataInputStream) {
    String header;
    try {
        header = typeID(dataInputStream);
    } catch (IOException ioException) {
        LOGGER.error("Could not read header from BEAM DataInputStream", ioException);
        return null;
    }
    if (!HEADER.equals(header)) {
        return null;
    }
    try {
        length(dataInputStream);
    } catch (IOException ioException) {
        LOGGER.error("Could not read length from BEAM DataInputStream", ioException);
        return null;
    }
    String section;
    try {
        section = typeID(dataInputStream);
    } catch (IOException ioException) {
        LOGGER.error("Could not read section header from BEAM DataInputStream", ioException);
        return null;
    }
    if (!"BEAM".equals(section)) {
        LOGGER.error("Section header is not BEAM");
        return null;
    }
    List<Chunk> chunkList = new ArrayList<Chunk>();
    int i = 1;
    while (true) {
        Chunk chunk;
        try {
            chunk = Chunk.from(dataInputStream);
        } catch (IOException ioException) {
            LOGGER.error("Could not read chunk number " + i + "from BEAM DataInputStream.  " + "Returning truncated Beam object", ioException);
            break;
        }
        if (chunk != null) {
            chunkList.add(chunk);
        } else {
            break;
        }
    }
    return new Beam(chunkList);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) Chunk(org.elixir_lang.beam.chunk.Chunk) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with Chunk

use of org.elixir_lang.beam.chunk.Chunk in project intellij-elixir by KronicDeth.

the class Beam method atoms.

/*
     * Instance Methods
     */
@Nullable
public Atoms atoms() {
    Atoms atoms = null;
    Chunk chunk = chunk(ATOM);
    if (chunk != null) {
        atoms = Atoms.from(chunk);
    }
    return atoms;
}
Also used : Atoms(org.elixir_lang.beam.chunk.Atoms) Chunk(org.elixir_lang.beam.chunk.Chunk) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with Chunk

use of org.elixir_lang.beam.chunk.Chunk in project intellij-elixir by KronicDeth.

the class Beam method exports.

@Nullable
public Exports exports() {
    Exports exports = null;
    Chunk chunk = chunk(EXPT);
    if (chunk != null) {
        exports = Exports.from(chunk);
    }
    return exports;
}
Also used : Chunk(org.elixir_lang.beam.chunk.Chunk) Exports(org.elixir_lang.beam.chunk.Exports) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

Chunk (org.elixir_lang.beam.chunk.Chunk)3 Nullable (org.jetbrains.annotations.Nullable)3 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Atoms (org.elixir_lang.beam.chunk.Atoms)1 Exports (org.elixir_lang.beam.chunk.Exports)1