Skip to content

Package: image_gif

image_gif

nameinstructionbranchcomplexitylinemethod
getContent(DataSource)
M: 57 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 14 C: 0
0%
M: 1 C: 0
0%
getDataFlavors()
M: 2 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
image_gif()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 13 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
writeTo(Object, String, OutputStream)
M: 41 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*
2: * Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
3: *
4: * This program and the accompanying materials are made available under the
5: * terms of the Eclipse Public License v. 2.0, which is available at
6: * http://www.eclipse.org/legal/epl-2.0.
7: *
8: * This Source Code may also be made available under the following Secondary
9: * Licenses when the conditions for such availability set forth in the
10: * Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11: * version 2 with the GNU Classpath Exception, which is available at
12: * https://www.gnu.org/software/classpath/license.html.
13: *
14: * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15: */
16:
17: package org.eclipse.angus.mail.handlers;
18:
19: import jakarta.activation.ActivationDataFlavor;
20: import jakarta.activation.DataSource;
21:
22: import java.awt.*;
23: import java.io.IOException;
24: import java.io.InputStream;
25: import java.io.OutputStream;
26:
27: /**
28: * DataContentHandler for image/gif.
29: */
30: public class image_gif extends handler_base {
31: private static ActivationDataFlavor[] myDF = {
32: new ActivationDataFlavor(Image.class, "image/gif", "GIF Image")
33: };
34:
35: /**
36: * Creates a default {@code image_gif}.
37: */
38: public image_gif() {
39: }
40:
41: @Override
42: protected ActivationDataFlavor[] getDataFlavors() {
43: return myDF;
44: }
45:
46: @Override
47: public Object getContent(DataSource ds) throws IOException {
48: InputStream is = ds.getInputStream();
49: int pos = 0;
50: int count;
51: byte[] buf = new byte[1024];
52:
53:• while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
54: pos += count;
55:• if (pos >= buf.length) {
56: int size = buf.length;
57: size += Math.min(size, 256 * 1024);
58: byte[] tbuf = new byte[size];
59: System.arraycopy(buf, 0, tbuf, 0, pos);
60: buf = tbuf;
61: }
62: }
63: Toolkit tk = Toolkit.getDefaultToolkit();
64: return tk.createImage(buf, 0, pos);
65: }
66:
67: /**
68: * Write the object to the output stream, using the specified MIME type.
69: */
70: @Override
71: public void writeTo(Object obj, String type, OutputStream os)
72: throws IOException {
73:• if (!(obj instanceof Image))
74: throw new IOException("\"" + getDataFlavors()[0].getMimeType() +
75: "\" DataContentHandler requires Image object, " +
76: "was given object of type " + obj.getClass().toString());
77:
78: throw new IOException(getDataFlavors()[0].getMimeType() +
79: " encoding not supported");
80: }
81: }