• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LearnLib / automatalib / 31586418187

12 Aug 2026 09:53AM UTC coverage: 92.921% (+0.9%) from 92.059%
31586418187

push

github

mtf90
use new version scheme

17615 of 18957 relevant lines covered (92.92%)

1.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/api/src/main/java/net/automatalib/serialization/ModelDeserializer.java
1
/* Copyright (C) 2013-2026 TU Dortmund University
2
 * This file is part of AutomataLib <https://automatalib.net>.
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package net.automatalib.serialization;
17

18
import java.io.ByteArrayInputStream;
19
import java.io.File;
20
import java.io.IOException;
21
import java.io.InputStream;
22
import java.net.URL;
23
import java.nio.charset.StandardCharsets;
24

25
import net.automatalib.common.util.IOUtil;
26
import net.automatalib.exception.FormatException;
27

28
/**
29
 * A generic interface for formalizing an arbitrary deserializer for a given model type.
30
 *
31
 * @param <M>
32
 *         the type of objects implementing classes can deserialize
33
 */
34
@FunctionalInterface
35
public interface ModelDeserializer<M> {
36

37
    /**
38
     * Reads the contents from the given input stream and de-serializes it into a model instance. If the format is a
39
     * textual one, the input stream is typically interpreted in {@link StandardCharsets#UTF_8 UTF-8}.
40
     * <p>
41
     * Note: the input stream will <b>not</b> be closed.
42
     *
43
     * @param is
44
     *         the input stream to read data from
45
     *
46
     * @return the de-serialized model
47
     *
48
     * @throws IOException
49
     *         if an error occurred while reading from the stream
50
     * @throws FormatException
51
     *         if the content of the stream was not in the expected format
52
     */
53
    M readModel(InputStream is) throws IOException, FormatException;
54

55
    /**
56
     * Reads the contents from the given URL and de-serializes it into a model instance. If the format is a textual one,
57
     * the input stream is typically interpreted in {@link StandardCharsets#UTF_8 UTF-8}.
58
     *
59
     * @param url
60
     *         the url to read data from
61
     *
62
     * @return the de-serialized model
63
     *
64
     * @throws IOException
65
     *         if an error occurred while reading from the stream
66
     * @throws FormatException
67
     *         if the content of the stream was not in the expected format
68
     */
69
    default M readModel(URL url) throws IOException, FormatException {
70
        try (InputStream is = IOUtil.asBufferedInputStream(url.openStream())) {
1✔
71
            return readModel(is);
1✔
72
        }
73
    }
74

75
    /**
76
     * Reads the contents from the given file and de-serializes it into a model instance. If the format is a textual
77
     * one, the input stream is typically interpreted in {@link StandardCharsets#UTF_8 UTF-8}.
78
     *
79
     * @param f
80
     *         the file to read data from
81
     *
82
     * @return the de-serialized model
83
     *
84
     * @throws IOException
85
     *         if an error occurred while reading from the stream
86
     * @throws FormatException
87
     *         if the content of the stream was not in the expected format
88
     */
89
    default M readModel(File f) throws IOException, FormatException {
90
        try (InputStream is = IOUtil.asBufferedInputStream(f)) {
1✔
91
            return readModel(is);
1✔
92
        }
93
    }
94

95
    /**
96
     * Reads the contents from the given byte buffer and de-serializes it into a model instance. If the format is a
97
     * textual one, the input stream is typically interpreted in {@link StandardCharsets#UTF_8 UTF-8}.
98
     *
99
     * @param buf
100
     *         the buffer to read data from
101
     *
102
     * @return the de-serialized model
103
     *
104
     * @throws IOException
105
     *         if an error occurred while reading from the stream
106
     * @throws FormatException
107
     *         if the content of the stream was not in the expected format
108
     */
109
    default M readModel(byte[] buf) throws IOException, FormatException {
110
        try (ByteArrayInputStream is = new ByteArrayInputStream(buf)) {
×
111
            return readModel(is);
×
112
        }
113
    }
114

115
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc