How the data for individual parts is stored is determined by the factory
30 | * used to create them; a given part may be in memory, on disk, or somewhere
31 | * else.
32 | *
33 | * @version $Id: FileUpload.java 1454690 2013-03-09 12:08:48Z simonetripodi $
34 | */
35 | public class FileUpload
36 | extends FileUploadBase {
37 |
38 | // ----------------------------------------------------------- Data members
39 |
40 | /**
41 | * The factory to use to create new form items.
42 | */
43 | private FileItemFactory fileItemFactory;
44 |
45 | // ----------------------------------------------------------- Constructors
46 |
47 | /**
48 | * Constructs an uninitialised instance of this class.
49 | *
50 | * A factory must be
51 | * configured, using setFileItemFactory(), before attempting
52 | * to parse requests.
53 | *
54 | * @see #FileUpload(FileItemFactory)
55 | */
56 | public FileUpload() {
57 | super();
58 | }
59 |
60 | /**
61 | * Constructs an instance of this class which uses the supplied factory to
62 | * create FileItem instances.
63 | *
64 | * @see #FileUpload()
65 | * @param fileItemFactory The factory to use for creating file items.
66 | */
67 | public FileUpload(FileItemFactory fileItemFactory) {
68 | super();
69 | this.fileItemFactory = fileItemFactory;
70 | }
71 |
72 | // ----------------------------------------------------- Property accessors
73 |
74 | /**
75 | * Returns the factory class used when creating file items.
76 | *
77 | * @return The factory class for new file items.
78 | */
79 | @Override
80 | public FileItemFactory getFileItemFactory() {
81 | return fileItemFactory;
82 | }
83 |
84 | /**
85 | * Sets the factory class to use when creating file items.
86 | *
87 | * @param factory The factory class for new file items.
88 | */
89 | @Override
90 | public void setFileItemFactory(FileItemFactory factory) {
91 | this.fileItemFactory = factory;
92 | }
93 |
94 | }
95 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/FileUploadException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload;
18 |
19 | import java.io.PrintStream;
20 | import java.io.PrintWriter;
21 |
22 | /**
23 | * Exception for errors encountered while processing the request.
24 | *
25 | * @version $Id: FileUploadException.java 1454690 2013-03-09 12:08:48Z simonetripodi $
26 | */
27 | public class FileUploadException extends Exception {
28 |
29 | /**
30 | * Serial version UID, being used, if the exception
31 | * is serialized.
32 | */
33 | private static final long serialVersionUID = 8881893724388807504L;
34 |
35 | /**
36 | * The exceptions cause. We overwrite the cause of
37 | * the super class, which isn't available in Java 1.3.
38 | */
39 | private final Throwable cause;
40 |
41 | /**
42 | * Constructs a new FileUploadException without message.
43 | */
44 | public FileUploadException() {
45 | this(null, null);
46 | }
47 |
48 | /**
49 | * Constructs a new FileUploadException with specified detail
50 | * message.
51 | *
52 | * @param msg the error message.
53 | */
54 | public FileUploadException(final String msg) {
55 | this(msg, null);
56 | }
57 |
58 | /**
59 | * Creates a new FileUploadException with the given
60 | * detail message and cause.
61 | *
62 | * @param msg The exceptions detail message.
63 | * @param cause The exceptions cause.
64 | */
65 | public FileUploadException(String msg, Throwable cause) {
66 | super(msg);
67 | this.cause = cause;
68 | }
69 |
70 | /**
71 | * Prints this throwable and its backtrace to the specified print stream.
72 | *
73 | * @param stream PrintStream to use for output
74 | */
75 | @Override
76 | public void printStackTrace(PrintStream stream) {
77 | super.printStackTrace(stream);
78 | if (cause != null) {
79 | stream.println("Caused by:");
80 | cause.printStackTrace(stream);
81 | }
82 | }
83 |
84 | /**
85 | * Prints this throwable and its backtrace to the specified
86 | * print writer.
87 | *
88 | * @param writer PrintWriter to use for output
89 | */
90 | @Override
91 | public void printStackTrace(PrintWriter writer) {
92 | super.printStackTrace(writer);
93 | if (cause != null) {
94 | writer.println("Caused by:");
95 | cause.printStackTrace(writer);
96 | }
97 | }
98 |
99 | /**
100 | * {@inheritDoc}
101 | */
102 | @Override
103 | public Throwable getCause() {
104 | return cause;
105 | }
106 |
107 | }
108 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/InvalidFileNameException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload;
18 |
19 | /**
20 | * This exception is thrown in case of an invalid file name.
21 | * A file name is invalid, if it contains a NUL character.
22 | * Attackers might use this to circumvent security checks:
23 | * For example, a malicious user might upload a file with the name
24 | * "foo.exe\0.png". This file name might pass security checks (i.e.
25 | * checks for the extension ".png"), while, depending on the underlying
26 | * C library, it might create a file named "foo.exe", as the NUL
27 | * character is the string terminator in C.
28 | *
29 | * @version $Id: InvalidFileNameException.java 1454691 2013-03-09 12:15:54Z simonetripodi $
30 | */
31 | public class InvalidFileNameException extends RuntimeException {
32 |
33 | /**
34 | * Serial version UID, being used, if the exception
35 | * is serialized.
36 | */
37 | private static final long serialVersionUID = 7922042602454350470L;
38 |
39 | /**
40 | * The file name causing the exception.
41 | */
42 | private final String name;
43 |
44 | /**
45 | * Creates a new instance.
46 | *
47 | * @param pName The file name causing the exception.
48 | * @param pMessage A human readable error message.
49 | */
50 | public InvalidFileNameException(String pName, String pMessage) {
51 | super(pMessage);
52 | name = pName;
53 | }
54 |
55 | /**
56 | * Returns the invalid file name.
57 | *
58 | * @return the invalid file name.
59 | */
60 | public String getName() {
61 | return name;
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/ProgressListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload;
18 |
19 | /**
20 | * The {@link ProgressListener} may be used to display a progress bar
21 | * or do stuff like that.
22 | *
23 | * @version $Id: ProgressListener.java 1454691 2013-03-09 12:15:54Z simonetripodi $
24 | */
25 | public interface ProgressListener {
26 |
27 | /**
28 | * Updates the listeners status information.
29 | *
30 | * @param pBytesRead The total number of bytes, which have been read
31 | * so far.
32 | * @param pContentLength The total number of bytes, which are being
33 | * read. May be -1, if this number is unknown.
34 | * @param pItems The number of the field, which is currently being
35 | * read. (0 = no item so far, 1 = first item is being read, ...)
36 | */
37 | void update(long pBytesRead, long pContentLength, int pItems);
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/RequestContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload;
18 |
19 | import java.io.IOException;
20 | import java.io.InputStream;
21 |
22 | /**
23 | *
Abstracts access to the request information needed for file uploads. This
24 | * interface should be implemented for each type of request that may be
25 | * handled by FileUpload, such as servlets and portlets.
26 | *
27 | * @since FileUpload 1.1
28 | *
29 | * @version $Id: RequestContext.java 1455861 2013-03-13 10:12:09Z simonetripodi $
30 | */
31 | public interface RequestContext {
32 |
33 | /**
34 | * Retrieve the character encoding for the request.
35 | *
36 | * @return The character encoding for the request.
37 | */
38 | String getCharacterEncoding();
39 |
40 | /**
41 | * Retrieve the content type of the request.
42 | *
43 | * @return The content type of the request.
44 | */
45 | String getContentType();
46 |
47 | /**
48 | * Retrieve the content length of the request.
49 | *
50 | * @return The content length of the request.
51 | * @deprecated 1.3 Use {@link UploadContext#contentLength()} instead
52 | */
53 | @Deprecated
54 | int getContentLength();
55 |
56 | /**
57 | * Retrieve the input stream for the request.
58 | *
59 | * @return The input stream for the request.
60 | *
61 | * @throws IOException if a problem occurs.
62 | */
63 | InputStream getInputStream() throws IOException;
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/UploadContext.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload;
18 |
19 | /**
20 | * Enhanced access to the request information needed for file uploads,
21 | * which fixes the Content Length data access in {@link RequestContext}.
22 | *
23 | * The reason of introducing this new interface is just for backward compatibility
24 | * and it might vanish for a refactored 2.x version moving the new method into
25 | * RequestContext again.
26 | *
27 | * @since 1.3
28 | */
29 | public interface UploadContext extends RequestContext {
30 |
31 | /**
32 | * Retrieve the content length of the request.
33 | *
34 | * @return The content length of the request.
35 | * @since 1.3
36 | */
37 | long contentLength();
38 |
39 | }
40 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/disk/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | *
20 | * A disk-based implementation of the
21 | * {@link org.apache.commons.fileupload.FileItem FileItem}
22 | * interface. This implementation retains smaller items in memory, while
23 | * writing larger ones to disk. The threshold between these two is
24 | * configurable, as is the location of files that are written to disk.
25 | *
26 | *
27 | * In typical usage, an instance of
28 | * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}
29 | * would be created, configured, and then passed to a
30 | * {@link org.apache.commons.fileupload.FileUpload FileUpload}
31 | * implementation such as
32 | * {@link org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload}
33 | * or
34 | * {@link org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload}.
35 | *
36 | *
37 | * The following code fragment demonstrates this usage.
38 | *
39 | *
40 | * DiskFileItemFactory factory = new DiskFileItemFactory();
41 | * // maximum size that will be stored in memory
42 | * factory.setSizeThreshold(4096);
43 | * // the location for saving data that is larger than getSizeThreshold()
44 | * factory.setRepository(new File("/tmp"));
45 | *
46 | * ServletFileUpload upload = new ServletFileUpload(factory);
47 | *
48 | *
49 | * Please see the FileUpload
50 | * User Guide
51 | * for further details and examples of how to use this package.
52 | *
53 | */
54 | package org.apache.commons.fileupload.disk;
55 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/httpserv/HttpServFileUpload.java:
--------------------------------------------------------------------------------
1 | package org.apache.commons.fileupload.httpserv;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 | import java.util.Map;
6 |
7 | import org.apache.commons.fileupload.FileItem;
8 | import org.apache.commons.fileupload.FileItemFactory;
9 | import org.apache.commons.fileupload.FileItemIterator;
10 | import org.apache.commons.fileupload.FileUpload;
11 | import org.apache.commons.fileupload.FileUploadBase;
12 | import org.apache.commons.fileupload.FileUploadException;
13 | import org.apache.http.HttpEntityEnclosingRequest;
14 | import org.apache.http.HttpRequest;
15 |
16 | public class HttpServFileUpload extends FileUpload {
17 |
18 | /** Constant for HTTP POST method. */
19 | private static final String POST_METHOD = "POST";
20 |
21 | public static final boolean isMultipartContent(HttpRequest request) {
22 | String method = request.getRequestLine().getMethod();
23 | if (!POST_METHOD.equalsIgnoreCase(method)) {
24 | return false;
25 | }
26 | if (!(request instanceof HttpEntityEnclosingRequest)) {
27 | return false;
28 | }
29 | return FileUploadBase.isMultipartContent(new HttpServRequestContext(
30 | (HttpEntityEnclosingRequest) request));
31 | }
32 |
33 | public HttpServFileUpload() {
34 | super();
35 | }
36 |
37 | public HttpServFileUpload(FileItemFactory fileItemFactory) {
38 | super(fileItemFactory);
39 | }
40 |
41 | public List parseRequest(HttpRequest request) throws FileUploadException {
42 | return parseRequest(new HttpServRequestContext(request));
43 | }
44 |
45 | public Map> parseParameterMap(HttpRequest request)
46 | throws FileUploadException {
47 | return parseParameterMap(new HttpServRequestContext(request));
48 | }
49 |
50 | public FileItemIterator getItemIterator(HttpRequest request) throws FileUploadException,
51 | IOException {
52 | return super.getItemIterator(new HttpServRequestContext(request));
53 | }
54 |
55 | }
56 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/httpserv/HttpServRequestContext.java:
--------------------------------------------------------------------------------
1 | package org.apache.commons.fileupload.httpserv;
2 |
3 | import static java.lang.String.format;
4 |
5 | import java.io.IOException;
6 | import java.io.InputStream;
7 |
8 | import org.apache.commons.fileupload.FileUploadException;
9 | import org.apache.commons.fileupload.UploadContext;
10 | import org.apache.http.Header;
11 | import org.apache.http.HttpEntity;
12 | import org.apache.http.HttpEntityEnclosingRequest;
13 | import org.apache.http.HttpRequest;
14 |
15 | public class HttpServRequestContext implements UploadContext {
16 |
17 | private final HttpEntityEnclosingRequest request;
18 | private final HttpEntity entity;
19 |
20 | public HttpServRequestContext(HttpRequest request) throws FileUploadException {
21 | if (!(request instanceof HttpEntityEnclosingRequest)) {
22 | throw new FileUploadException(
23 | "Unacceptable HttpRequest, it must be instanceof HttpEntityEnclosingRequest");
24 | }
25 | this.request = ((HttpEntityEnclosingRequest) request);
26 | this.entity = this.request.getEntity();
27 | }
28 |
29 | public HttpServRequestContext(HttpEntityEnclosingRequest request) {
30 | this.request = request;
31 | this.entity = request.getEntity();
32 | }
33 |
34 | @Override
35 | public String getCharacterEncoding() {
36 | Header header = entity.getContentEncoding();
37 | return header == null ? null : header.getValue();
38 | }
39 |
40 | @Override
41 | public String getContentType() {
42 | Header header = entity.getContentType();
43 | return header == null ? null : header.getValue();
44 | }
45 |
46 | @Override
47 | public int getContentLength() {
48 | return (int) entity.getContentLength();
49 | }
50 |
51 | @Override
52 | public long contentLength() {
53 | return entity.getContentLength();
54 | }
55 |
56 | @Override
57 | public InputStream getInputStream() throws IOException {
58 | return entity.getContent();
59 | }
60 |
61 | @Override
62 | public String toString() {
63 | return format("ContentLength=%s, ContentType=%s", this.contentLength(),
64 | this.getContentType());
65 | }
66 |
67 | }
68 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | *
20 | * A component for handling HTML file uploads as specified by
21 | * RFC 1867.
22 | * This component provides support for uploads within both servlets (JSR 53)
23 | * and portlets (JSR 168).
24 | *
25 | *
26 | * While this package provides the generic functionality for file uploads,
27 | * these classes are not typically used directly. Instead, normal usage
28 | * involves one of the provided extensions of
29 | * {@link org.apache.commons.fileupload.FileUpload FileUpload} such as
30 | * {@link org.apache.commons.fileupload.servlet.ServletFileUpload ServletFileUpload}
31 | * or
32 | * {@link org.apache.commons.fileupload.portlet.PortletFileUpload PortletFileUpload},
33 | * together with a factory for
34 | * {@link org.apache.commons.fileupload.FileItem FileItem} instances,
35 | * such as
36 | * {@link org.apache.commons.fileupload.disk.DiskFileItemFactory DiskFileItemFactory}.
37 | *
38 | *
39 | * The following is a brief example of typical usage in a servlet, storing
40 | * the uploaded files on disk.
41 | *
42 | *
public void doPost(HttpServletRequest req, HttpServletResponse res) {
43 | * DiskFileItemFactory factory = new DiskFileItemFactory();
44 | * // maximum size that will be stored in memory
45 | * factory.setSizeThreshold(4096);
46 | * // the location for saving data that is larger than getSizeThreshold()
47 | * factory.setRepository(new File("/tmp"));
48 | *
49 | * ServletFileUpload upload = new ServletFileUpload(factory);
50 | * // maximum size before a FileUploadException will be thrown
51 | * upload.setSizeMax(1000000);
52 | *
53 | * List fileItems = upload.parseRequest(req);
54 | * // assume we know there are two files. The first file is a small
55 | * // text file, the second is unknown and is written to a file on
56 | * // the server
57 | * Iterator i = fileItems.iterator();
58 | * String comment = ((FileItem)i.next()).getString();
59 | * FileItem fi = (FileItem)i.next();
60 | * // filename on the client
61 | * String fileName = fi.getName();
62 | * // save comment and filename to database
63 | * ...
64 | * // write the file
65 | * fi.write(new File("/www/uploads/", fileName));
66 | * }
67 | *
68 | *
69 | * In the example above, the first file is loaded into memory as a
70 | * String. Before calling the getString method,
71 | * the data may have been in memory or on disk depending on its size. The
72 | * second file we assume it will be large and therefore never explicitly
73 | * load it into memory, though if it is less than 4096 bytes it will be
74 | * in memory before it is written to its final location. When writing to
75 | * the final location, if the data is larger than the threshold, an attempt
76 | * is made to rename the temporary file to the given location. If it cannot
77 | * be renamed, it is streamed to the new location.
78 | *
79 | *
80 | * Please see the FileUpload
81 | * User Guide
82 | * for further details and examples of how to use this package.
83 | *
84 | */
85 | package org.apache.commons.fileupload;
86 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/util/Closeable.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload.util;
18 |
19 | import java.io.IOException;
20 |
21 | /**
22 | * Interface of an object, which may be closed.
23 | *
24 | * @version $Id: Closeable.java 1454691 2013-03-09 12:15:54Z simonetripodi $
25 | */
26 | public interface Closeable {
27 |
28 | /**
29 | * Closes the object.
30 | *
31 | * @throws IOException An I/O error occurred.
32 | */
33 | void close() throws IOException;
34 |
35 | /**
36 | * Returns, whether the object is already closed.
37 | *
38 | * @return True, if the object is closed, otherwise false.
39 | * @throws IOException An I/O error occurred.
40 | */
41 | boolean isClosed() throws IOException;
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/util/FileItemHeadersImpl.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload.util;
18 |
19 | import java.io.Serializable;
20 | import java.util.ArrayList;
21 | import java.util.Collections;
22 | import java.util.Iterator;
23 | import java.util.LinkedHashMap;
24 | import java.util.List;
25 | import java.util.Locale;
26 | import java.util.Map;
27 |
28 | import org.apache.commons.fileupload.FileItemHeaders;
29 |
30 | /**
31 | * Default implementation of the {@link FileItemHeaders} interface.
32 | *
33 | * @since 1.2.1
34 | *
35 | * @version $Id: FileItemHeadersImpl.java 1458379 2013-03-19 16:16:47Z britter $
36 | */
37 | public class FileItemHeadersImpl implements FileItemHeaders, Serializable {
38 |
39 | /**
40 | * Serial version UID, being used, if serialized.
41 | */
42 | private static final long serialVersionUID = -4455695752627032559L;
43 |
44 | /**
45 | * Map of String keys to a List of
46 | * String instances.
47 | */
48 | private final Map> headerNameToValueListMap = new LinkedHashMap>();
49 |
50 | /**
51 | * {@inheritDoc}
52 | */
53 | public String getHeader(String name) {
54 | String nameLower = name.toLowerCase(Locale.ENGLISH);
55 | List headerValueList = headerNameToValueListMap.get(nameLower);
56 | if (null == headerValueList) {
57 | return null;
58 | }
59 | return headerValueList.get(0);
60 | }
61 |
62 | /**
63 | * {@inheritDoc}
64 | */
65 | public Iterator getHeaderNames() {
66 | return headerNameToValueListMap.keySet().iterator();
67 | }
68 |
69 | /**
70 | * {@inheritDoc}
71 | */
72 | public Iterator getHeaders(String name) {
73 | String nameLower = name.toLowerCase(Locale.ENGLISH);
74 | List headerValueList = headerNameToValueListMap.get(nameLower);
75 | if (null == headerValueList) {
76 | headerValueList = Collections.emptyList();
77 | }
78 | return headerValueList.iterator();
79 | }
80 |
81 | /**
82 | * Method to add header values to this instance.
83 | *
84 | * @param name name of this header
85 | * @param value value of this header
86 | */
87 | public synchronized void addHeader(String name, String value) {
88 | String nameLower = name.toLowerCase(Locale.ENGLISH);
89 | List headerValueList = headerNameToValueListMap.get(nameLower);
90 | if (null == headerValueList) {
91 | headerValueList = new ArrayList();
92 | headerNameToValueListMap.put(nameLower, headerValueList);
93 | }
94 | headerValueList.add(value);
95 | }
96 |
97 | }
98 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/util/mime/ParseException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 | package org.apache.commons.fileupload.util.mime;
18 |
19 | /**
20 | * @since 1.3
21 | */
22 | final class ParseException extends Exception {
23 |
24 | /**
25 | * The UID to use when serializing this instance.
26 | */
27 | private static final long serialVersionUID = 5355281266579392077L;
28 |
29 | /**
30 | * Constructs a new exception with the specified detail message.
31 | *
32 | * @param message the detail message.
33 | */
34 | public ParseException(String message) {
35 | super(message);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/util/mime/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * MIME decoder implementation, imported and retailed from
20 | * Apache Geronimo.
21 | */
22 | package org.apache.commons.fileupload.util.mime;
23 |
--------------------------------------------------------------------------------
/src/upload/org/apache/commons/fileupload/util/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Licensed to the Apache Software Foundation (ASF) under one or more
3 | * contributor license agreements. See the NOTICE file distributed with
4 | * this work for additional information regarding copyright ownership.
5 | * The ASF licenses this file to You under the Apache License, Version 2.0
6 | * (the "License"); you may not use this file except in compliance with
7 | * the License. You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | /**
19 | * This package contains various IO related utility classes
20 | * or methods, which are basically reusable and not necessarily
21 | * restricted to the scope of a file upload.
22 | */
23 | package org.apache.commons.fileupload.util;
24 |
--------------------------------------------------------------------------------
/src/zxing/org/join/zxing/AmbientLightManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 ZXing authors
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 |
17 | package org.join.zxing;
18 |
19 | import org.join.zxing.camera.CameraManager;
20 | import org.join.zxing.camera.FrontLightMode;
21 |
22 | import android.content.Context;
23 | import android.content.SharedPreferences;
24 | import android.hardware.Sensor;
25 | import android.hardware.SensorEvent;
26 | import android.hardware.SensorEventListener;
27 | import android.hardware.SensorManager;
28 | import android.preference.PreferenceManager;
29 |
30 | /**
31 | * Detects ambient light and switches on the front light when very dark, and off again when sufficiently light.
32 | *
33 | * @author Sean Owen
34 | * @author Nikolaus Huber
35 | */
36 | final class AmbientLightManager implements SensorEventListener {
37 |
38 | private static final float TOO_DARK_LUX = 45.0f;
39 | private static final float BRIGHT_ENOUGH_LUX = 450.0f;
40 |
41 | private final Context context;
42 | private CameraManager cameraManager;
43 | private Sensor lightSensor;
44 |
45 | AmbientLightManager(Context context) {
46 | this.context = context;
47 | }
48 |
49 | void start(CameraManager cameraManager) {
50 | this.cameraManager = cameraManager;
51 | SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
52 | if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
53 | SensorManager sensorManager = (SensorManager) context
54 | .getSystemService(Context.SENSOR_SERVICE);
55 | lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
56 | if (lightSensor != null) {
57 | sensorManager
58 | .registerListener(this, lightSensor, SensorManager.SENSOR_DELAY_NORMAL);
59 | }
60 | }
61 | }
62 |
63 | void stop() {
64 | if (lightSensor != null) {
65 | SensorManager sensorManager = (SensorManager) context
66 | .getSystemService(Context.SENSOR_SERVICE);
67 | sensorManager.unregisterListener(this);
68 | cameraManager = null;
69 | lightSensor = null;
70 | }
71 | }
72 |
73 | @Override
74 | public void onSensorChanged(SensorEvent sensorEvent) {
75 | float ambientLightLux = sensorEvent.values[0];
76 | if (cameraManager != null) {
77 | if (ambientLightLux <= TOO_DARK_LUX) {
78 | cameraManager.setTorch(true);
79 | } else if (ambientLightLux >= BRIGHT_ENOUGH_LUX) {
80 | cameraManager.setTorch(false);
81 | }
82 | }
83 | }
84 |
85 | @Override
86 | public void onAccuracyChanged(Sensor sensor, int accuracy) {
87 | // do nothing
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/zxing/org/join/zxing/DecodeFormatManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
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 |
17 | package org.join.zxing;
18 |
19 | import java.util.Arrays;
20 | import java.util.Collection;
21 | import java.util.EnumSet;
22 | import java.util.List;
23 | import java.util.regex.Pattern;
24 |
25 | import android.content.Intent;
26 | import android.net.Uri;
27 |
28 | import com.google.zxing.BarcodeFormat;
29 |
30 | final class DecodeFormatManager {
31 |
32 | private static final Pattern COMMA_PATTERN = Pattern.compile(",");
33 |
34 | static final Collection PRODUCT_FORMATS;
35 | static final Collection ONE_D_FORMATS;
36 | static final Collection QR_CODE_FORMATS = EnumSet.of(BarcodeFormat.QR_CODE);
37 | static final Collection DATA_MATRIX_FORMATS = EnumSet
38 | .of(BarcodeFormat.DATA_MATRIX);
39 | static {
40 | PRODUCT_FORMATS = EnumSet.of(BarcodeFormat.UPC_A, BarcodeFormat.UPC_E,
41 | BarcodeFormat.EAN_13, BarcodeFormat.EAN_8, BarcodeFormat.RSS_14,
42 | BarcodeFormat.RSS_EXPANDED);
43 | ONE_D_FORMATS = EnumSet.of(BarcodeFormat.CODE_39, BarcodeFormat.CODE_93,
44 | BarcodeFormat.CODE_128, BarcodeFormat.ITF, BarcodeFormat.CODABAR);
45 | ONE_D_FORMATS.addAll(PRODUCT_FORMATS);
46 | }
47 |
48 | private DecodeFormatManager() {
49 | }
50 |
51 | static Collection parseDecodeFormats(Intent intent) {
52 | List scanFormats = null;
53 | String scanFormatsString = intent.getStringExtra(Intents.Scan.FORMATS);
54 | if (scanFormatsString != null) {
55 | scanFormats = Arrays.asList(COMMA_PATTERN.split(scanFormatsString));
56 | }
57 | return parseDecodeFormats(scanFormats, intent.getStringExtra(Intents.Scan.MODE));
58 | }
59 |
60 | static Collection parseDecodeFormats(Uri inputUri) {
61 | List formats = inputUri.getQueryParameters(Intents.Scan.FORMATS);
62 | if (formats != null && formats.size() == 1 && formats.get(0) != null) {
63 | formats = Arrays.asList(COMMA_PATTERN.split(formats.get(0)));
64 | }
65 | return parseDecodeFormats(formats, inputUri.getQueryParameter(Intents.Scan.MODE));
66 | }
67 |
68 | private static Collection parseDecodeFormats(Iterable scanFormats,
69 | String decodeMode) {
70 | if (scanFormats != null) {
71 | Collection formats = EnumSet.noneOf(BarcodeFormat.class);
72 | try {
73 | for (String format : scanFormats) {
74 | formats.add(BarcodeFormat.valueOf(format));
75 | }
76 | return formats;
77 | } catch (IllegalArgumentException iae) {
78 | // ignore it then
79 | }
80 | }
81 | if (decodeMode != null) {
82 | if (Intents.Scan.PRODUCT_MODE.equals(decodeMode)) {
83 | return PRODUCT_FORMATS;
84 | }
85 | if (Intents.Scan.QR_CODE_MODE.equals(decodeMode)) {
86 | return QR_CODE_FORMATS;
87 | }
88 | if (Intents.Scan.DATA_MATRIX_MODE.equals(decodeMode)) {
89 | return DATA_MATRIX_FORMATS;
90 | }
91 | if (Intents.Scan.ONE_D_MODE.equals(decodeMode)) {
92 | return ONE_D_FORMATS;
93 | }
94 | }
95 | return null;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/src/zxing/org/join/zxing/DecodeThread.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2008 ZXing authors
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 |
17 | package org.join.zxing;
18 |
19 | import java.util.Collection;
20 | import java.util.EnumMap;
21 | import java.util.EnumSet;
22 | import java.util.Map;
23 | import java.util.concurrent.CountDownLatch;
24 |
25 | import android.content.SharedPreferences;
26 | import android.os.Handler;
27 | import android.os.Looper;
28 | import android.preference.PreferenceManager;
29 | import android.util.Log;
30 |
31 | import com.google.zxing.BarcodeFormat;
32 | import com.google.zxing.DecodeHintType;
33 | import com.google.zxing.ResultPointCallback;
34 |
35 | /**
36 | * This thread does all the heavy lifting of decoding the images.
37 | *
38 | * @author dswitkin@google.com (Daniel Switkin)
39 | */
40 | final class DecodeThread extends Thread {
41 |
42 | public static final String BARCODE_BITMAP = "barcode_bitmap";
43 | public static final String BARCODE_SCALED_FACTOR = "barcode_scaled_factor";
44 |
45 | private final CaptureActivity activity;
46 | private final Map hints;
47 | private Handler handler;
48 | private final CountDownLatch handlerInitLatch;
49 |
50 | DecodeThread(CaptureActivity activity, Collection decodeFormats,
51 | Map baseHints, String characterSet,
52 | ResultPointCallback resultPointCallback) {
53 |
54 | this.activity = activity;
55 | handlerInitLatch = new CountDownLatch(1);
56 |
57 | hints = new EnumMap(DecodeHintType.class);
58 | if (baseHints != null) {
59 | hints.putAll(baseHints);
60 | }
61 |
62 | // The prefs can't change while the thread is running, so pick them up once here.
63 | if (decodeFormats == null || decodeFormats.isEmpty()) {
64 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
65 | decodeFormats = EnumSet.noneOf(BarcodeFormat.class);
66 | if (prefs.getBoolean(ZXingPreferences.KEY_DECODE_1D, false)) {
67 | decodeFormats.addAll(DecodeFormatManager.ONE_D_FORMATS);
68 | }
69 | if (prefs.getBoolean(ZXingPreferences.KEY_DECODE_QR, false)) {
70 | decodeFormats.addAll(DecodeFormatManager.QR_CODE_FORMATS);
71 | }
72 | if (prefs.getBoolean(ZXingPreferences.KEY_DECODE_DATA_MATRIX, false)) {
73 | decodeFormats.addAll(DecodeFormatManager.DATA_MATRIX_FORMATS);
74 | }
75 | }
76 | hints.put(DecodeHintType.POSSIBLE_FORMATS, decodeFormats);
77 |
78 | if (characterSet != null) {
79 | hints.put(DecodeHintType.CHARACTER_SET, characterSet);
80 | }
81 | hints.put(DecodeHintType.NEED_RESULT_POINT_CALLBACK, resultPointCallback);
82 | Log.i("DecodeThread", "Hints: " + hints);
83 | }
84 |
85 | Handler getHandler() {
86 | try {
87 | handlerInitLatch.await();
88 | } catch (InterruptedException ie) {
89 | // continue?
90 | }
91 | return handler;
92 | }
93 |
94 | @Override
95 | public void run() {
96 | Looper.prepare();
97 | handler = new DecodeHandler(activity, hints);
98 | handlerInitLatch.countDown();
99 | Looper.loop();
100 | }
101 |
102 | }
103 |
--------------------------------------------------------------------------------
/src/zxing/org/join/zxing/FinishListener.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
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 |
17 | package org.join.zxing;
18 |
19 | import android.app.Activity;
20 | import android.content.DialogInterface;
21 |
22 | /**
23 | * Simple listener used to exit the app in a few cases.
24 | *
25 | * @author Sean Owen
26 | */
27 | public final class FinishListener implements DialogInterface.OnClickListener, DialogInterface.OnCancelListener {
28 |
29 | private final Activity activityToFinish;
30 |
31 | public FinishListener(Activity activityToFinish) {
32 | this.activityToFinish = activityToFinish;
33 | }
34 |
35 | @Override
36 | public void onCancel(DialogInterface dialogInterface) {
37 | run();
38 | }
39 |
40 | @Override
41 | public void onClick(DialogInterface dialogInterface, int i) {
42 | run();
43 | }
44 |
45 | private void run() {
46 | activityToFinish.finish();
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/zxing/org/join/zxing/InactivityTimer.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2010 ZXing authors
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 |
17 | package org.join.zxing;
18 |
19 | import org.join.zxing.common.executor.AsyncTaskExecInterface;
20 | import org.join.zxing.common.executor.AsyncTaskExecManager;
21 |
22 | import android.app.Activity;
23 | import android.content.BroadcastReceiver;
24 | import android.content.Context;
25 | import android.content.Intent;
26 | import android.content.IntentFilter;
27 | import android.os.AsyncTask;
28 | import android.os.BatteryManager;
29 | import android.util.Log;
30 |
31 | /**
32 | * Finishes an activity after a period of inactivity if the device is on battery power.
33 | */
34 | final class InactivityTimer {
35 |
36 | private static final String TAG = InactivityTimer.class.getSimpleName();
37 |
38 | private static final long INACTIVITY_DELAY_MS = 5 * 60 * 1000L;
39 |
40 | private final Activity activity;
41 | private final AsyncTaskExecInterface taskExec;
42 | private final BroadcastReceiver powerStatusReceiver;
43 | private InactivityAsyncTask inactivityTask;
44 |
45 | InactivityTimer(Activity activity) {
46 | this.activity = activity;
47 | taskExec = new AsyncTaskExecManager().build();
48 | powerStatusReceiver = new PowerStatusReceiver();
49 | onActivity();
50 | }
51 |
52 | synchronized void onActivity() {
53 | cancel();
54 | inactivityTask = new InactivityAsyncTask();
55 | taskExec.execute(inactivityTask);
56 | }
57 |
58 | public void onPause() {
59 | cancel();
60 | activity.unregisterReceiver(powerStatusReceiver);
61 | }
62 |
63 | public void onResume() {
64 | activity.registerReceiver(powerStatusReceiver, new IntentFilter(
65 | Intent.ACTION_BATTERY_CHANGED));
66 | onActivity();
67 | }
68 |
69 | private synchronized void cancel() {
70 | AsyncTask, ?, ?> task = inactivityTask;
71 | if (task != null) {
72 | task.cancel(true);
73 | inactivityTask = null;
74 | }
75 | }
76 |
77 | void shutdown() {
78 | cancel();
79 | }
80 |
81 | private final class PowerStatusReceiver extends BroadcastReceiver {
82 | @Override
83 | public void onReceive(Context context, Intent intent) {
84 | if (Intent.ACTION_BATTERY_CHANGED.equals(intent.getAction())) {
85 | // 0 indicates that we're on battery
86 | boolean onBatteryNow = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1) <= 0;
87 | if (onBatteryNow) {
88 | InactivityTimer.this.onActivity();
89 | } else {
90 | InactivityTimer.this.cancel();
91 | }
92 | }
93 | }
94 | }
95 |
96 | private final class InactivityAsyncTask extends AsyncTask