/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* Reads all of the data from the system Clipboard which the data transfer
* subsystem knows how to translate. This includes all text data, File Lists,
* Serializable objects, Remote objects, and properly registered, arbitrary
* data as InputStreams. The data is stored in byte format until requested
* by client code. At that point, the data is converted, if necessary, into
* the proper format to deliver to the application.
*
* This hybrid pre-fetch/delayed-rendering approach allows us to circumvent
* the API restriction that client code cannot lock the Clipboard to discover
* its formats before requesting data in a particular format, while avoiding
* the overhead of fully rendering all data ahead of time.
*
* @author David Mendenhall
* @author Danila Sinopalnikov
*
* @since 1.4 (appeared in modified form as FullyRenderedTransferable in 1.3.1)
*/
private final class DataFactory {
final long format;
final byte[] data;
}
return DataTransferer.getInstance().
ClipboardTransferable.this);
}
}
try {
// Since the SystemFlavorMap will specify many DataFlavors
// which map to the same format, we should cache data as we
// read it.
{
}
}
} finally {
}
}
{
try {
} catch (IOException e) {
data = e;
} catch (Throwable e) {
e.printStackTrace();
}
// Cache this data, even if it's null, so we don't have to go
// to native code again for this format.
} else {
}
// Casting IOException to byte array causes ClassCastException.
// We should handle IOException separately - do not wrap them into
// DataFactory and report failure.
if (data instanceof IOException) {
return false;
(byte[])data));
return true;
}
}
return false;
}
}
}
{
if (!isDataFlavorSupported(flavor)) {
throw new UnsupportedFlavorException(flavor);
}
if (ret instanceof IOException) {
// rethrow IOExceptions generated while fetching data
throw (IOException)ret;
} else if (ret instanceof DataFactory) {
// Now we can render the data
}
return ret;
}
}