001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.json.data;
016    
017    import com.liferay.portal.kernel.util.Base64;
018    import com.liferay.portal.kernel.util.FileUtil;
019    
020    import java.io.File;
021    import java.io.IOException;
022    
023    /**
024     * @author Igor Spasic
025     */
026    public class FileData {
027    
028            public FileData(File file) {
029                    byte[] bytes = null;
030    
031                    try {
032                            bytes = FileUtil.getBytes(file);
033                    }
034                    catch (IOException ioe) {
035                            bytes = null;
036                    }
037    
038                    _content = Base64.encode(bytes);
039    
040                    _name = file.getName();
041                    _size = file.length();
042            }
043    
044            public String getContent() {
045                    return _content;
046            }
047    
048            public String getName() {
049                    return _name;
050            }
051    
052            public long getSize() {
053                    return _size;
054            }
055    
056            public void setContent(String content) {
057                    _content = content;
058            }
059    
060            public void setName(String name) {
061                    _name = name;
062            }
063    
064            public void setSize(long size) {
065                    _size = size;
066            }
067    
068            private String _content;
069            private String _name;
070            private long _size;
071    
072    }