Skip to content

Package: image_gif

image_gif

nameinstructionbranchcomplexitylinemethod
getContent(DataSource)
M: 63 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 16 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: 26 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.Image;
23: import java.awt.Toolkit;
24: import java.io.IOException;
25: import java.io.InputStream;
26: import java.io.OutputStream;
27:
28: /**
29: * DataContentHandler for image/gif.
30: */
31: public class image_gif extends handler_base {
32: private static ActivationDataFlavor[] myDF = {
33:         new ActivationDataFlavor(Image.class, "image/gif", "GIF Image")
34: };
35:
36: /**
37: * Creates a default {@code image_gif}.
38: */
39: public image_gif() {
40: }
41:
42: @Override
43: protected ActivationDataFlavor[] getDataFlavors() {
44:         return myDF;
45: }
46:
47: @Override
48: public Object getContent(DataSource ds) throws IOException {
49:         InputStream is = ds.getInputStream();
50:         int pos = 0;
51:         int count;
52:         byte buf[] = new byte[1024];
53:
54:•        while ((count = is.read(buf, pos, buf.length - pos)) != -1) {
55:          pos += count;
56:•         if (pos >= buf.length) {
57:                 int size = buf.length;
58:•                if (size < 256*1024)
59:                  size += size;
60:                 else
61:                  size += 256*1024;
62:                 byte tbuf[] = new byte[size];
63:                 System.arraycopy(buf, 0, tbuf, 0, pos);
64:                 buf = tbuf;
65:          }
66:         }
67:         Toolkit tk = Toolkit.getDefaultToolkit();
68:         return tk.createImage(buf, 0, pos);
69: }
70:
71: /**
72: * Write the object to the output stream, using the specified MIME type.
73: */
74: @Override
75: public void writeTo(Object obj, String type, OutputStream os)
76:                         throws IOException {
77:•        if (!(obj instanceof Image))
78:          throw new IOException("\"" + getDataFlavors()[0].getMimeType() +
79:                 "\" DataContentHandler requires Image object, " +
80:                 "was given object of type " + obj.getClass().toString());
81:
82:         throw new IOException(getDataFlavors()[0].getMimeType() +
83:                                 " encoding not supported");
84: }
85: }