001/* 002 * Copyright (c) 2004-2013 Tada AB and other contributors, as listed below. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the The BSD 3-Clause License 006 * which accompanies this distribution, and is available at 007 * http://opensource.org/licenses/BSD-3-Clause 008 * 009 * Contributors: 010 * Tada AB 011 */ 012package org.postgresql.pljava.example; 013 014import java.io.File; 015import java.io.IOException; 016import java.sql.SQLException; 017 018/** 019 * Provides a {@link #createTempFile createTempFile} function, expected to fail 020 * if it is declared with the <em>trusted</em> {@code java} language. 021 */ 022public class Security { 023 /** 024 * The following method should fail if the language in use is trusted. 025 * 026 * @return The name of a created temporary file. 027 * @throws SQLException 028 */ 029 public static String createTempFile() throws SQLException { 030 try { 031 File tmp = File.createTempFile("pljava", ".test"); 032 tmp.deleteOnExit(); 033 return tmp.getAbsolutePath(); 034 } catch (IOException e) { 035 throw new SQLException(e.getMessage()); 036 } 037 } 038}