CASampledSP
Loading...
Searching...
No Matches
CAUtils.cpp
Go to the documentation of this file.
1/*
2 * =================================================
3 * Copyright 2011 tagtraum industries incorporated
4 * This file is part of CASampledSP.
5 *
6 * CASampledSP is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * CASampledSP is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with CASampledSP; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 * =================================================
20 *
21 * @author <a href="mailto:hs@tagtraum.com">Hendrik Schreiber</a>
22 */
23#include "CAUtils.h"
24
25
29static void fourLetterCode(int err, char *cbuf) {
30 cbuf[0] = ((char*)&err)[3];
31 cbuf[1] = ((char*)&err)[2];
32 cbuf[2] = ((char*)&err)[1];
33 cbuf[3] = ((char*)&err)[0];
34}
35
39void throwUnsupportedAudioFileExceptionIfError(JNIEnv *env, int err, const char * message) {
40 if (err) {
41#ifdef DEBUG
42 fprintf (stderr, "UnsupportedAudioFileException: '%s' %d (%4.4s)\n", message, (int)err, (char*)&err);
43#endif
44 char cbuf[4];
45 fourLetterCode(err, cbuf);
46 char formattedMessage [strlen(message)+8];
47 snprintf(formattedMessage, strlen(message)+8, "%s (%4.4s)", message, cbuf);
48 jclass excCls = env->FindClass("javax/sound/sampled/UnsupportedAudioFileException");
49 env->ThrowNew(excCls, formattedMessage);
50 }
51}
52
56void throwIOExceptionIfError(JNIEnv *env, int err, const char *message) {
57 if (err) {
58#ifdef DEBUG
59 fprintf (stderr, "IOException: '%s' %d (%4.4s)\n", message, (int)err, (char*)&err);
60#endif
61 char cbuf[4];
62 fourLetterCode(err, cbuf);
63 char formattedMessage [strlen(message)+8];
64 snprintf(formattedMessage, strlen(message)+8, "%s (%4.4s)", message, cbuf);
65 jclass excCls = env->FindClass("java/io/IOException");
66 env->ThrowNew(excCls, formattedMessage);
67 }
68}
69
73void throwIllegalArgumentExceptionIfError(JNIEnv *env, int err, const char *message) {
74 if (err) {
75#ifdef DEBUG
76 fprintf (stderr, "IllegalArgumentException: '%s' %d (%4.4s)\n", message, (int)err, (char*)&err);
77#endif
78 char cbuf[4];
79 fourLetterCode(err, cbuf);
80 char formattedMessage [strlen(message)+8];
81 snprintf(formattedMessage, strlen(message)+8, "%s (%4.4s)", message, cbuf);
82 jclass excCls = env->FindClass("java/lang/IllegalArgumentException");
83 env->ThrowNew(excCls, formattedMessage);
84
85 }
86}
90void throwFileNotFoundExceptionIfError(JNIEnv *env, int err, const char *message) {
91 if (err) {
92 //fprintf (stderr, "FileNotFoundException: '%s' %d (%4.4s)\n", message, (int)err, (char*)&err);
93 jclass excCls = env->FindClass("java/io/FileNotFoundException");
94 env->ThrowNew(excCls, message);
95 }
96}
97
101void ca_create_url_ref(JNIEnv *env, jstring path, CFURLRef &urlRef) {
102 const jchar *chars = env->GetStringChars(path, NULL);
103 CFStringRef cfPath = CFStringCreateWithCharacters (kCFAllocatorDefault, chars, env->GetStringLength(path));
104 env->ReleaseStringChars(path, chars);
105 urlRef = CFURLCreateWithString(kCFAllocatorDefault, cfPath, NULL);
106 CFRelease(cfPath);
107}
void throwFileNotFoundExceptionIfError(JNIEnv *env, int err, const char *message)
Throws an IllegalArgumentException.
Definition CAUtils.cpp:90
void throwIllegalArgumentExceptionIfError(JNIEnv *env, int err, const char *message)
Throws an IllegalArgumentException.
Definition CAUtils.cpp:73
void throwUnsupportedAudioFileExceptionIfError(JNIEnv *env, int err, const char *message)
Throws an UnsupportedAudioFileException exception.
Definition CAUtils.cpp:39
void throwIOExceptionIfError(JNIEnv *env, int err, const char *message)
Throws an IOException.
Definition CAUtils.cpp:56
void ca_create_url_ref(JNIEnv *env, jstring path, CFURLRef &urlRef)
Creates a CFURLRef from the given path.
Definition CAUtils.cpp:101