feedme java project

is free software, licensed under the terms of the GNU General Public License, that feeds/imports media from anywhere to xbox360 media center extenders, ipods, web servers, file servers, etc. using Java.

Please read the license here.

Thursday, September 25, 2008

ffmpeg -formats

File formats:
E 3g2 3GP2 format
E 3gp 3GP format
D 4xm 4X Technologies format
D IFF IFF format
D MTV MTV format
DE RoQ id RoQ format
D aac ADTS AAC
DE ac3 raw AC-3
E adts ADTS AAC
DE aiff Audio IFF
DE alaw pcm A law format
DE amr 3GPP AMR file format
D apc CRYO APC format
D ape Monkey's Audio
DE asf ASF format
E asf_stream ASF format
DE au SUN AU format
DE avi AVI format
E avm2 Flash 9 (AVM2) format
D avs AVISynth
D bethsoftvid Bethesda Softworks VID format
D bfi Brute Force & Ignorance
D c93 Interplay C93
E crc CRC testing format
D daud D-Cinema audio format
DE dirac raw Dirac
D dsicin Delphine Software International CIN format
DE dts raw DTS
DE dv DV video format
E dvd MPEG-2 PS format (DVD VOB)
D dxa DXA
D ea Electronic Arts Multimedia Format
D ea_cdata Electronic Arts cdata
DE ffm ffm format
D film_cpk Sega FILM/CPK format
DE flac raw FLAC
D flic FLI/FLC/FLX animation format
DE flv FLV format
E framecrc framecrc testing format
DE gif GIF Animation
D gsm GSM
DE gxf GXF format
DE h261 raw H.261
DE h263 raw H.263
DE h264 raw H.264 video format
D idcin id CIN format
DE image2 image2 sequence
DE image2pipe piped image2 sequence
D ingenient Ingenient MJPEG
D ipmovie Interplay MVE format
E ipod iPod H.264 MP4 format
D lmlm4 lmlm4 raw format
DE m4v raw MPEG-4 video format
DE matroska Matroska file format
DE mjpeg MJPEG video
D mlp raw MLP
D mm American Laser Games MM format
DE mmf mmf format
E mov MOV format
D mov,mp4,m4a,3gp,3g2,mj2 QuickTime/MPEG-4/Motion JPEG 2000 format
E mp2 MPEG audio layer 2
DE mp3 MPEG audio layer 3
E mp4 MP4 format
D mpc Musepack
D mpc8 Musepack SV8
DE mpeg MPEG-1 System format
E mpeg1video MPEG video
E mpeg2video MPEG-2 video
DE mpegts MPEG-2 transport stream format
D mpegtsraw MPEG-2 raw transport stream format
D mpegvideo MPEG video
E mpjpeg Mime multipart JPEG format
D msnwctcp MSN TCP Webcam stream
DE mulaw pcm mu law format
D mxf MXF format
D nsv NullSoft Video format
E null null video format
DE nut NUT format
D nuv NuppelVideo format
DE ogg Ogg
D oma Sony OpenMG audio
E psp PSP MP4 format
D psxstr Sony Playstation STR format
D pva TechnoTrend PVA file and stream format
DE rawvideo raw video format
D redir Redirector format
D rl2 rl2 format
DE rm RM format
D rpl RPL/ARMovie format
E rtp RTP output format
D rtsp RTSP input format
DE s16be pcm signed 16 bit big endian format
DE s16le pcm signed 16 bit little endian format
DE s8 pcm signed 8 bit format
D sdp SDP
D shn raw Shorten
D siff Beam Software SIFF
D smk Smacker video
D sol Sierra SOL format
E svcd MPEG-2 PS format (VOB)
DE swf Flash format
D thp THP
D tiertexseq Tiertex Limited SEQ format
D tta True Audio
D txd txd format
DE u16be pcm unsigned 16 bit big endian format
DE u16le pcm unsigned 16 bit little endian format
DE u8 pcm unsigned 8 bit format
D vc1 raw VC-1
D vc1test VC-1 test bitstream format
E vcd MPEG-1 System format (VCD)
D vfwcap VFW video capture
D vmd Sierra VMD format
E vob MPEG-2 PS format (VOB)
DE voc Creative Voice file format
DE wav WAV format
D wc3movie Wing Commander III movie format
D wsaud Westwood Studios audio format
D wsvqa Westwood Studios VQA format
D wv WavPack
D xa Maxis XA File Format
DE yuv4mpegpipe YUV4MPEG pipe format

Codecs:
D V 4xm 4X Movie
D V D 8bps QuickTime 8BPS video
D A 8svx_exp 8SVX exponential
D A 8svx_fib 8SVX fibonacci
D V D aasc Autodesk RLE
EA ac3 ATSC A/52 / AC-3
D A adpcm_4xm 4X Movie ADPCM
DEA adpcm_adx SEGA CRI ADX
D A adpcm_ct Creative Technology ADPCM
D A adpcm_ea Electronic Arts ADPCM
D A adpcm_ea_maxis_xa Electronic Arts Maxis CDROM XA ADPCM
D A adpcm_ea_r1 Electronic Arts R1 ADPCM
D A adpcm_ea_r2 Electronic Arts R2 ADPCM
D A adpcm_ea_r3 Electronic Arts R3 ADPCM
D A adpcm_ea_xas Electronic Arts XAS ADPCM
D A adpcm_ima_amv IMA AMV ADPCM
D A adpcm_ima_dk3 IMA Duck DK3 ADPCM
D A adpcm_ima_dk4 IMA Duck DK4 ADPCM
D A adpcm_ima_ea_eacs IMA Electronic Arts EACS ADPCM
D A adpcm_ima_ea_sead IMA Electronic Arts SEAD ADPCM
DEA adpcm_ima_qt IMA QuickTime ADPCM
D A adpcm_ima_smjpeg IMA Loki SDL MJPEG ADPCM
DEA adpcm_ima_wav IMA Wav ADPCM
D A adpcm_ima_ws IMA Westwood ADPCM
DEA adpcm_ms Microsoft ADPCM
D A adpcm_sbpro_2 Sound Blaster Pro 2-bit ADPCM
D A adpcm_sbpro_3 Sound Blaster Pro 2.6-bit ADPCM
D A adpcm_sbpro_4 Sound Blaster Pro 4-bit ADPCM
DEA adpcm_swf Shockwave Flash ADPCM
D A adpcm_thp Nintendo Gamecube THP ADPCM
D A adpcm_xa CDROM XA ADPCM
DEA adpcm_yamaha Yamaha ADPCM
D A alac ALAC (Apple Lossless Audio Codec)
D V amv AMV Video
D A ape Monkey's Audio
DEV D asv1 ASUS V1
DEV D asv2 ASUS V2
D A atrac3 Atrac 3 (Adaptive TRansform Acoustic Coding 3)
D V D avs AVS (Audio Video Standard) video
D V bethsoftvid Bethesda VID video
D V bfi Brute Force & Ignorance
DEV bmp BMP image
D V D c93 Interplay C93
D V D camstudio CamStudio
D V D camtasia TechSmith Screen Capture Codec
D V D cavs Chinese AVS video (AVS1-P2, JiZhun profile)
D V D cinepak Cinepak
D V D cljr Cirrus Logic AccuPak
D A cook COOK
D V D cyuv Creative YUV (CYUV)
D A dca DCA (DTS Coherent Acoustics)
DEV D dnxhd VC3/DNxHD
D A dsicinaudio Delphine Software International CIN audio
D V D dsicinvideo Delphine Software International CIN video
DES dvbsub DVB subtitles
DES dvdsub DVD subtitles
DEV D dvvideo DV (Digital Video)
D V dxa Feeble Files/ScummVM DXA
D V D escape124 Escape 124
DEV D ffv1 FFmpeg codec #1
DEVSD ffvhuff Huffyuv FFmpeg variant
DEA flac FLAC (Free Lossless Audio Codec)
DEV D flashsv Flash Screen Video
D V D flic Autodesk Animator Flic video
DEVSD flv Flash Video
D V D fraps Fraps
DEA g726 G.726 ADPCM
DEV gif GIF (Graphics Interchange Format)
DEV D h261 H.261
DEVSDT h263 H.263
D VSD h263i H.263i
EV h263p H.263+ / H.263 version 2
D V DT h264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
DEVSD huffyuv Huffyuv / HuffYUV
D V D idcinvideo id Quake II CIN video
D A imc IMC (Intel Music Coder)
D V D indeo2 Intel Indeo 2
D V indeo3 Intel Indeo 3
D A interplay_dpcm Interplay DPCM
D V D interplayvideo Interplay MVE Video
DEV D jpegls JPEG-LS
D V kmvc Karl Morton's video codec
D A liba52 liba52 ATSC A/52 / AC-3
EA libfaac libfaac AAC (Advanced Audio Codec)
D A libfaad libfaad AAC (Advanced Audio Codec)
DEA libgsm libgsm GSM
DEA libgsm_ms libgsm GSM Microsoft variant
EA libmp3lame libmp3lame MP3 (MPEG audio layer 3)
EV libtheora libtheora Theora
EA libvorbis libvorbis Vorbis
EV libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10
EV libxvid libxvidcore MPEG-4 part 2
EV ljpeg Lossless JPEG
D V D loco LOCO
D A mace3 MACE (Macintosh Audio Compression/Expansion) 3:1
D A mace6 MACE (Macintosh Audio Compression/Expansion) 6:1
D V D mdec Sony PlayStation MDEC (Motion DECoder)
D V D mimic Mimic
DEV D mjpeg MJPEG (Motion JPEG)
D V D mjpegb Apple MJPEG-B
D V D mmvideo American Laser Games MM Video
DEA mp2 MP2 (MPEG audio layer 2)
D A mp3 MP3 (MPEG audio layer 3)
D A mp3adu ADU (Application Data Unit) MP3 (MPEG audio layer 3)
D A mp3on4 MP3onMP4
D A mpc7 Musepack SV7
D A mpc8 Musepack SV8
DEVSDT mpeg1video MPEG-1 video
DEVSDT mpeg2video MPEG-2 video
DEVSDT mpeg4 MPEG-4 part 2
D A mpeg4aac libfaad AAC (Advanced Audio Codec)
D VSDT mpegvideo MPEG-1 video
DEVSD msmpeg4 MPEG-4 part 2 Microsoft variant version 3
DEVSD msmpeg4v1 MPEG-4 part 2 Microsoft variant version 1
DEVSD msmpeg4v2 MPEG-4 part 2 Microsoft variant version 2
D V D msrle Microsoft RLE
D V D msvideo1 Microsoft Video 1
D V D mszh LCL (LossLess Codec Library) MSZH
D A nellymoser Nellymoser Asao
D V D nuv NuppelVideo
DEV pam PAM (Portable AnyMap) image
DEV pbm PBM (Portable BitMap) image
DEA pcm_alaw A-law PCM
D A pcm_dvd signed 16|20|24-bit big-endian PCM
DEA pcm_mulaw mu-law PCM
DEA pcm_s16be signed 16-bit big-endian PCM
DEA pcm_s16le signed 16-bit little-endian PCM
D A pcm_s16le_planar 16-bit little-endian planar PCM
DEA pcm_s24be signed 24-bit big-endian PCM
DEA pcm_s24daud D-Cinema audio signed 24-bit PCM
DEA pcm_s24le signed 24-bit little-endian PCM
DEA pcm_s32be signed 32-bit big-endian PCM
DEA pcm_s32le signed 32-bit little-endian PCM
DEA pcm_s8 signed 8-bit PCM
DEA pcm_u16be unsigned 16-bit big-endian PCM
DEA pcm_u16le unsigned 16-bit little-endian PCM
DEA pcm_u24be unsigned 24-bit big-endian PCM
DEA pcm_u24le unsigned 24-bit little-endian PCM
DEA pcm_u32be unsigned 32-bit big-endian PCM
DEA pcm_u32le unsigned 32-bit little-endian PCM
DEA pcm_u8 unsigned 8-bit PCM
DEA pcm_zork Zork PCM
D V pcx PC Paintbrush PCX image
DEV pgm PGM (Portable GrayMap) image
DEV pgmyuv PGMYUV (Portable GrayMap YUV) image
DEV png PNG image
DEV ppm PPM (Portable PixelMap) image
D V ptx V.Flash PTX image
D A qdm2 QDesign Music Codec 2
D V D qdraw Apple QuickDraw
D V D qpeg Q-team QPEG
DEV D qtrle QuickTime Animation (RLE) video
DEV rawvideo raw video
D A real_144 RealAudio 1.0 (14.4K)
D A real_288 RealAudio 2.0 (28.8K)
D V D rl2 RL2 video
DEA roq_dpcm id RoQ DPCM
DEV D roqvideo id RoQ video
D V D rpza QuickTime video (RPZA)
DEV D rv10 RealVideo 1.0
DEV D rv20 RealVideo 2.0
DEV sgi SGI image
D A shorten Shorten
D A smackaud Smacker audio
D V smackvid Smacker video
D V D smc QuickTime Graphics (SMC)
DEV snow Snow
D A sol_dpcm Sol DPCM
DEA sonic Sonic
EA sonicls Sonic lossless
D V D sp5x Sunplus JPEG (SP5X)
D V sunrast Sun Rasterfile image
DEV D svq1 Sorenson Vector Quantizer 1
D VSD svq3 Sorenson Vector Quantizer 3
DEV targa Truevision Targa image
D V theora Theora
D V D thp Nintendo Gamecube THP video
D V D tiertexseqvideo Tiertex Limited SEQ video
DEV tiff TIFF image
D V D truemotion1 Duck TrueMotion 1.0
D V D truemotion2 Duck TrueMotion 2.0
D A truespeech DSP Group TrueSpeech
D A tta True Audio
D V txd Renderware TXD (TeXture Dictionary) image
D V D ultimotion IBM UltiMotion
D V vb Beam Software VB
D V vc1 SMPTE VC-1
D V D vcr1 ATI VCR1
D A vmdaudio Sierra VMD audio
D V D vmdvideo Sierra VMD video
D V vmnc VMware Screen Codec / VMware Video
DEA vorbis Vorbis
D V vp3 On2 VP3
D V D vp5 On2 VP5
D V D vp6 On2 VP6
D V D vp6a On2 VP6 (Flash version, with alpha channel)
D V D vp6f On2 VP6 (Flash version)
D V D vqavideo Westwood Studios VQA (Vector Quantized Animation) video
D A wavpack WavPack
DEA wmav1 Windows Media Audio 1
DEA wmav2 Windows Media Audio 2
DEVSD wmv1 Windows Media Video 7
DEVSD wmv2 Windows Media Video 8
D V wmv3 Windows Media Video 9
D V D wnv1 Winnov WNV1
D A ws_snd1 Westwood Audio (SND1)
D A xan_dpcm Xan DPCM
D V D xan_wc3 Wing Commander III / Xan
D V D xl Miro VideoXL
D S xsub XSUB
DEV D zlib LCL (LossLess Codec Library) ZLIB
DEV zmbv Zip Motion Blocks Video

Monday, August 18, 2008

avi to ipod


ffmpeg -i in.avi -f psp -r 29.97 -b 768k -ar 24000 -ab 64k -s 320x240 out.mp4

ffmpeg -i in.avi -vcodec h264 -s 320x240 -acodec aac -ab 128 -f mov out.mov

ffmpeg -i in.avi -vcodec h264 -s 320x240 -acodec aac -ab 128 -f mp4 out.mp4

Saturday, August 2, 2008

Ubuntu 64-Bit JVM


daddy@heron:~$ uname -a
Linux heron 2.6.24-19-generic #1 SMP Fri Jul 11 21:01:46 UTC 2008 x86_64 GNU/Linux

Saturday, March 1, 2008

Main.java 08202007

init:
deps-jar:
compile:
run:
C:\Documents and Settings\jmcloske\feedme

//////// //////// //////// ///////
// // // // //
///// ///// ///// // //
// // // // //
// //////// //////// ///////

/// /// ////////
//// //// //
// // // // /////
// /// // //
// // // ////////

It's now Mon Aug 20 22:20:30 ACT 2007
You chose to open this file: GI Joe Valor vs. Venom.avi
BUILD SUCCESSFUL (total time: 4 seconds)

/*
* Main.java
* Created on June 31, 2007, 9:19 PM
*/

package feedme;

import java.awt.Component;
import java.io.*;
import java.nio.*;
import java.util.*;
import javax.script.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author john mcloskey
*/
public class Main {

private static Component parent;

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
String curDir = System.getProperty("user.dir");
System.out.println(curDir);
ArrayList list = new ArrayList();

list.add( new String(" //////// //////// //////// /////// ") );
list.add( new String(" // // // // // ") );
list.add( new String(" ///// ///// ///// // // ") );
list.add( new String(" // // // // // ") );
list.add( new String(" // //////// //////// /////// ") );
list.add( new String(" ") );
list.add( new String(" /// /// //////// ") );
list.add( new String(" //// //// // ") );
list.add( new String(" // // // // ///// ") );
list.add( new String(" // /// // // ") );
list.add( new String(" // // // //////// ") );
//list.add( new StringBuffer() );

for( String str : list ) {
System.out.println( str );
}

File w = new File("feedme.wip");
// Wed Aug 01 21:21:56 CDT 2007
// Stream to write file feedme.wip
// "crack the wip" file here
FileOutputStream fout;

try {
// Open an output stream
fout = new FileOutputStream("feedme.wip");

// Print a line of text
new PrintStream(fout).println(new Date(Calendar.getInstance().getTimeInMillis()));

// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e) {
System.err.println("Unable to write to wip file");
System.exit(-1);
}
System.out.println("It's now " + new Date(Calendar.getInstance().getTimeInMillis()));
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"AVI encoded video files", "avi");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
}

//example jsEngine.eval from javax.script.*
/*ScriptEngineManager mgr = new ScriptEngineManager();
List factories =
mgr.getEngineFactories();
for (ScriptEngineFactory factory: factories) {
System.out.println("ScriptEngineFactory Info");
String engName = factory.getEngineName();
String engVersion = factory.getEngineVersion();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
System.out.printf("\tScript Engine: %s (%s)\n",
engName, engVersion);
List engNames = factory.getNames();
for(String name: engNames) {
System.out.printf("\tEngine Alias: %s\n", name);
}
System.out.printf("\tLanguage: %s (%s)\n",
langName, langVersion);
}
try {
jsEngine.eval("print('Hello, world!')");
} catch (ScriptException ex) {
ex.printStackTrace();
}*/

// August 15, 2007, 7:43 PM - osx out.ipod.mp4 @export method added

/**
* remove the "//" below to @export out.ipod.mp4 to current directory
*/

// :sout="#transcode{vcodec=mp4v,vb=1024,scale=1, \
// acodec=mp4a,ab=128,channels=2}:standard{access=file, \
// url=out.ipod.mp4}" vlc:quit \
// --aspect-ratio "4:3" --sout-transcode-width 360 \
// --sout-transcode-height 240 --sout-transcode-fps 30

// August 1, 2007, 7:00 PM - linux, osx, and HDDVD output formats added

/**
* remove the "//" below to enable hdiutil out.dvd.dmg @export on osx platform
* updated Wed Aug 04 01:53:00 CDT 2007
*/

// Runtime.getRuntime().exec( "hdiutil create -megabytes 4096 -fs HFS+ \
// -volname FeedMeOutVol out.dvd.dmg" );

/**
* remove the "//" below to enable QTFU6 windows @import method.
* Windows QTFU6 @import method added 08/04/2007.
*/

// Runtime.getRuntime().exec( "C:\Program Files\iTunes\itunes.exe /regserv
// C:\...\QTFairUse\QTFairUse6console.exe --Process all" );

/**
* remove first "//" below to enable Linux /usr/bin/streamripper @import method.
* remove second "//" below to enable BSD /usr/pkg/bin/streamripper @import method.
* Linux and BSD @import methods added Wed Aug 04 2007.
*/

// Runtime.getRuntime().exec( "/usr/bin/streamripper http://di.fm:8095/");
// Runtime.getRuntime().exec( "/usr/pkg/bin/streamripper http://di.fm:8095/");


//(copy) streams of the following kinds:
//.mp3 Shoutcast streams - the kind of streams found on shoutcast.com.
//.mp3 Icecast streams
//.nvs (Nullsoft Streaming Video) streams
//.aac Shoutcast/Icecast streams
//.ogg stream

/**
* remove the "//" below to @import in.avi on osx platform
* updated Wed Aug 03 16:53:00 CDT 2007
*/

//Runtime.getRuntime().exec(
// /Applications/VLC.app/Contents/MacOS/VLC -vvv in.avi --sout-ffmpeg-qscale 1

/**
* remove the "//" below to @import in.avi on windows platform
*/

//Runtime.getRuntime().exec(
//"C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv in.avi --sout-ffmpeg-qscale 1

/**
* remove the "//" below to @import in.avi on linux platform
*/

//Runtime.getRuntime().exec(
//"/usr/bin/vlc" -vvv ./in.avi --sout-ffmpeg-qscale 1

/**
* remove the "//" below to @export out.dvd.wmv to current directory
* in 720x480 wmv media center standard DVD format
*/

//:sout=#transcode{vcodec=WMV2,width=720,height=480,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})


/**
* remove the "//" below to @export out.hd720p.wmv to current directory
* in 1280(width) 720(height) native media center HDDVD 720p format
*/

//:sout=#transcode{vcodec=WMV2,width=1280,height=720,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})


/**
* remove the "//" below to @export out.hd1080p.wmv to current directory
* in 1920 (width) x 1080 (height) native media center HDDVD 1080p format
*/

//:sout=#transcode{vcodec=WMV2,width=1920,height=1080,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})
}

}

Saturday, November 17, 2007

UNIX BIBLE


UNIX BIBLE
~~~~ ~~~~~

Command Description
~~~~~~~ ~~~~~~~~~~~

awk Search for a pattern within a file. Includes
a built-in programming language.

bdiff Compares two large files.

bfs Scans a large file.

cal Displays a calendar.

cat Concatenates and prints files.

cc C compiler.

cd Change directory.

chgrp Changes a file's group ownership.

chmod Changes a file's access permissions.

chown Changes the individual ownership of a file.

cmp Compares two files; diplays the location (line
and byte) of the 1st difference between these.

comm Compares two files so as to determine which
lines are common to both.

cp Copies a file to another location.

cu Calls another UNIX system.

date Returns the date and time.

df Displays free space in the file system.

diff Displays the differences between two files
or directories.

diff3 Displays the differences between three files
or directories.

du Reports on file system usage.

echo Displays its argument.

ed Text editor.

ex Text editor.

expr Evaluates its argument which is generally
a mathematical formula.

f77 FORTRAN compiler.

find Locates the files w/ specified characteristics.

format Initializes a floppy disk.

grep Searches for a pattern within a file. (see awk)

help Salvation.

kill Ends a process.

ln Used to link files.

lpr Copies the file to the line printer.

ls Displays info. about one or more files.

mail Used to receive or deliver e-mail.

mkdir Creates a new directory.

more Displays a long file so that the user
can scroll through it.

mv Used to move or rename files.

nroff Used to format text.

ps Display a process's status.

pwd Display the name of the working directory.

rm Removes one or more files.

rmdir Deletes one or more directories.

sleep Causes a process to become inactive for a
specified length of time.

sort Sort and merge one or more files.

spell Finds spelling errors in a file.

split Divides a file.

stty Display or set terminal parameters.

tail Displays the end of a file.

troff Outputs formatted output to a typesetter.

tset Sets the terminal type.

umask Allows the user to specify a new creation
mask.

uniq Compares 2 files. Finds and displays lines
in one file that are unique.

uucp UNIX-to-UNIX execute.

vi Full screen editor.

wc Displays details in the file size.

who Info. on who else be online.

write Used to send a message to another user.
______________________________________________________________________________
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

awk program filenames
awk -f programfilenames filenames
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The [awk] utility can be used to find any lines in a file which
match a certain pattern; once found, these lines can be processed.
In the first configuration, the program that [awk] is to
execute is specified in the command line. In the second,
the program is stored as the file given in programfilename.
The -f option instructs [awk] to read this file.

[bdiff] is used to compare files too large for [diff]. See
[diff] for the format.

bfs filename
~~~~~~~~~~~~
[bfs] is used to scan a large file to determine where to split
it into smaller files.

cal 01-12 (month) 0-9999 (year)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[cal] utility can be used to display a calendar of any year
from 0 to 9999 AD, and any or all of the twelve months.

cat filename
~~~~~~~~~~~~
[cat] can be used to examine a short file. See [more] for
lengthier files.

number[cc]
~~~~~~~~~~
The [cc] command changes the entire current line, or a group
of lines starting with the current line. [number] represents
the number of old lines to be deleted.

cd directory name
~~~~~~~~~~~~~~~~~
The [cd] command causes the current working directory to be
changed. The [directory name] can be either a full or partial
path name.

chgrp groupname filename
~~~~~~~~~~~~~~~~~~~~~~~~
This command changes the group ownership of a file.

chmod {ugoa} {+-} {rwx}
~~~~~~~~~~~~~~~~~~~~~~~
The [chmod] utility changes a file's access permissions. [u]
specifies the user or owner's login name, [g] specifies a group
and [o] indicates all others. [a] indicates the user, group,
and all others; c'est the default. [+] adds permission; [-]
deletes it. [r] indicates read, [w] write, and [x] execute.

chown individualname filename
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[chown] changes the individual ownership of a file (see chgrp).

cmp filename1 filename2
~~~~~~~~~~~~~~~~~~~~~~~
[cmp] is one of the four principle UNIX file comparison utilities.
It compares 2 files, and returns the positions where they differ.

comm -options filename1 filename2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The [comm] utility, in comparing two files, produces three
columns of output. The first contains lines unique to the
first file, the second, lines unique to the second, and the
third column, lines common to both files. By placing the
numbers [1], [2], and/or [3] in the [options] position, any
one (or more) of these columns can be suppressed.

cp sendingfile receivingfile
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The [cp] command copies a file. [sendingfile] is the file to be
copied, [receivingfile] is the file to which it is copied.

diff [options] filename1 filename2
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Again, a file comparison utility. However, with [diff], the
differences are displayed as instructions that can be used
to edit the files so that they are identical.

diff3 filename1 filename2 filename3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Similar to [diff], [diff3] is unique in that it can compare
three files. Gee.

ed filename
~~~~~~~~~~~
One of the UNIX's three editing utilities, [ed] is a basic line
editor. I'm sure there are other files that will explain how
to use [ed]. Thus, I'll confine myself to a rough outline:
e filename ........... edit a different file
f filename ........... changes the currently specified file.
h .................... provides explanation of errors.
I
text ................. inserts text before the current line.
line,linel ........... lists the specified lines.
line,linen ........... displays specified lines, preceded by
their line numbers.
q .................... exit from [ed]
w .................... writes buffer to current filename.
+ or - ............... +number of lines closer to end
-number of lines closer to beginning.

expr formula
~~~~~~~~~~~~
Utility which evaluates an expression.

find directory searchcriteria parameter actioncriteria parameter
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The [find] utility can be very useful indeed, especially when
confronted by a UNIX with countless files. Basically, this
command finds files which meet certain criteria, and then
performs an operation (such as printing the files). Search
criteria consists of the following:


Criteria Parameter Description
~~~~~~~~ ~~~~~~~~~ ~~~~~~~~~~~
-name filename Files whose names match [filename]
will meet this criteria.
-type filetype Files whose type matches that specified
[b] block special will meet criteria.
[c] character spec. file
[d] directory file
[f] plain file
-links +/- x Files with # of links indicated by
+ or - x meet this criteria.
-user login name Files belonging to user with given
or user ID # login name or ID # meet criteria.
-group group name Files belonging to group with given
or group ID # group name or ID # meet this criteria.
-size + or - x Files greater than +x bytes or less
than -x bytes meet this criteria.
-atime + or - x Files not accessed within +x days,
accessed within -x days, or acc-
essed x days ago meet criteria.
-mtime + or - x Files NOT modified within +x days,
modified within -x days, or modified
x days ago will meet this criteria.
-newer filename Files modified more recently than
[filename] meet this criteria.
Action Criteria " "
~~~~~~~~~~~~~~~ ~ ~
-print - When search criteria are met, path
name of the file is displayed.
-exec command{ }\; Executes given command when search
criteria are met. { } indicates file-
name, [\;] ends the command.
-ok command{ }\; Exactly like -exec, except user is
prompted [y] or [n] before command.

grep -options searchstring filenames
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Another search command, this for a particular string of chars.

ln original new
~~~~~~~~~~~~~~~
[ln] establishes a file link. For this utility, [original] repre-
sents the filename to be linked, [new] the filename of the new
link to the original.


[ls] provides directory information. [ls -l/] displays a more
complete version of the info. list.

mail username username
~~~~~~~~~~~~~~~~~~~~~~
This utility allows e-mail to be sent to other system users.

mail
~~~~
Simply typing [mail] checks the user's own mailbox.
When sending mail, several items must be set:
~s text ............ sets the subject field
~c user names ...... sends other users carbon copies of mail
m user names ....... activates the compose mode, with the
specified users as the message's recipients.
~h ................. displays and allows editing of all headers.
^D ................. ends message editing; sends mail.
~r filename ........ places file in body of message (keen command)
Reading One's Own Mail:
h number or range ....... causes specified headers to be displayed
p message # ............. displays entire message
d number or range ....... deletes specified messages
u number or range ....... undelete specified mail during SAME
mail session (messages removed after q)
q ....................... leave the post office

mkdir directoryname
~~~~~~~~~~~~~~~~~~~
[mkdir] allows creation of a subdirectory, for your dining
enjoyment.

more filename
~~~~~~~~~~~~~
For longer files, [more] is a convenient utility. It will display
the first screen of file data and then stop, allowing the user
to control scrolling henceforth.

mv oldfilename newfilename
~~~~~~~~~~~~~~~~~~~~~~~~~~
The [mv] utility can be used simply to rename a file, or...

mv filea fileb... directory
~~~~~~~~~~~~~~~~~~~~~~~~~~~
[mv] can also be used to move files to a new directory, provided
the directory exists, and you have write access to it.

ps -options
~~~~~~~~~~~
The [ps] command, by itself, displays the status of each active
process controlled by your terminal. This status report includes
the Process Identification Number (PID), the terminal (TTY), the
time the process has been executing (TIME), and the command line
used to execute the process (CMD).
[ps]'s three options include -a (displays info. on active processes
controlled by any terminal), -x (info. on ALL active processes), and
-l (an extensive status report on all active processes).

pwd
~~~
[pwd] command displays the present working directory.

rm filename
~~~~~~~~~~~
[rm] removes a file. More than one file can be specified.

rmdir directoryname
~~~~~~~~~~~~~~~~~~~
This utility removes a directory, an EMPTY directory (save the
hidden files).

sleep seconds
~~~~~~~~~~~~~
The [sleep] utility causes a process to become inactive for a
certain period of time. Max. seconds is 65,536 (about 18 hrs).

sort -options filenames
~~~~~~~~~~~~~~~~~~~~~~~
[sort] merges and sorts files. Without options, [sort] orders
files by the ASCII codes of the characters at the beginning
of each line. Options include -b (leading blanks ignored), -d
(only letters, digs, and blanks considered; "dictionary sort"),
-f (case ignored), -n (numerical sort [for numerical data]), and
-r (a reverse sort).

split -size original resulting
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[split] divides a large file into smaller ones. [size] refers to
the number of lines the resulting files contain, [original] is
the name of the orig. file, and [resulting] represents the
prefix name assigned to the newly created files.

umask ugo
~~~~~~~~~
[umask] changes the file CREATION mask (see [chmod] for already
existing files). Here, [u] represents the owner's access
permission, [g] the group's a.p., and [o] the a.p. for all others.

[uucp] (UNIX to UNIX copy) can be used to send files to a
remote UNIX, or retrieve files from the remote system.
Other UNIX comm commands include [cu] (which establishes contact
with another system), and [uux] (UNIX to UNIX execute; allows
commands to be executed on a remote system).

wc -options filenames
~~~~~~~~~~~~~~~~~~~~~
The [wc] utility displays file-size information. This includes
the number of lines, words, and characters. By chosing the
-l, -w, or -c options, the information can be limited to only
line, word, or character number.

who
~~~
A very useful command (which some systems respond to even before
a user is actually logged on), [who] displays a list of users
currently online. This list includes the user's name, terminal
device # (tty), and the log-in time. [who am i] displays info.
only on the user who executed the command.
No fate, but what we make.

Tuesday, September 18, 2007

vlc-help.txt


Usage: vlc.exe [options] [stream] ...
You can specify multiple streams on the commandline. They will be enqueued in the playlist.
The first item specified will be played first.

Options-styles:
--option A global option that is set for the duration of the program.
-option A single letter version of a global --option.
:option An option that only applies to the stream directly before it
and that overrides previous settings.

Stream MRL syntax:
[[access][/demux]://]URL[@[title][:chapter][-[title][:chapter]]] [:option=value ...]

Many of the global --options can also be used as MRL specific :options.
Multiple :option=value pairs can be specified.

URL syntax:
[file://]filename Plain media file
http://ip:port/file HTTP URL
ftp://ip:port/file FTP URL
mms://ip:port/file MMS URL
screen:// Screen capture
[dvd://][device][@raw_device] DVD device
[vcd://][device] VCD device
[cdda://][device] Audio CD device
udp:[[]@[][:]]
UDP stream sent by a streaming server
vlc:pause: Special item to pause the playlist for a certain time
vlc:quit Special item to quit VLC

Help options
-h, --help print help for VLC (can be combined with
--advanced)
-H, --longhelp print help for VLC and all its modules (can
be combined with --advanced)
--advanced print help for the advanced options
--help-verbose ask for extra verbosity when displaying help
-l, --list print a list of available modules
-p, --module print help on a specific module (can be
combined with --advanced)
--save-config save the current command line options in the
config
--reset-config reset the current config to the default values
--config use alternate config file
--reset-plugins-cache resets the current plugins cache
--version print version information

Audio
--audio, --no-audio Enable audio (default enabled)
--volume Default audio volume
--spdif, --no-spdif Use S/PDIF when available (default disabled)
--force-dolby-surround {0 (Auto), 1 (On), 2 (Off)}
Force detection of Dolby Surround
--audio-filter Audio filters
--audio-visual Audio visualizations

Video
-f, --fullscreen, --no-fullscreen
Fullscreen video output (default disabled)
--overlay, --no-overlay Overlay video output (default enabled)
--video-on-top, --no-video-on-top
Always on top (default disabled)
--snapshot-path Video snapshot directory (or filename)
--snapshot-prefix Video snapshot file prefix
--snapshot-format {png,jpg}
Video snapshot format
--snapshot-preview, --no-snapshot-preview
Display video snapshot preview (default
enabled)
--snapshot-sequential, --no-snapshot-sequential
Use sequential numbers instead of timestamps
(default disabled)
--crop Video cropping
--custom-crop-ratios
Custom crop ratios list
--aspect-ratio Source aspect ratio
--custom-aspect-ratios
Custom aspect ratios list
--vout-filter Video filter module

Subpictures
--osd, --no-osd On Screen Display (default enabled)
--sub-file Use subtitle file
--sub-autodetect-file, --no-sub-autodetect-file
Autodetect subtitle files (default enabled)
--sub-filter Subpictures filter module
--audio-language Audio language
--sub-language Subtitle language
--input-repeat Input repetitions
--dvd DVD device
--vcd VCD device
--cd-audio Audio CD device
--server-port UDP port
-6, --ipv6, --no-ipv6 Force IPv6 (default disabled)
-4, --ipv4, --no-ipv4 Force IPv4 (default disabled)

Input
--access-filter Access filter module
--high-priority, --no-high-priority
Increase the priority of the process (default
disabled)

Playlist
-Z, --random, --no-random Play files randomly forever (default disabled)
-L, --loop, --no-loop Repeat all (default disabled)
-R, --repeat, --no-repeat Repeat current item (default disabled)
--play-and-stop, --no-play-and-stop
Play and stop (default disabled)
--open Default stream
--auto-preparse, --no-auto-preparse
Automatically preparse files (default enabled)
-S, --services-discovery
Services discovery modules
-v, --verbose Verbosity (0,1,2)
--language {auto,en,en_GB,ar,ca,cs,da,de,es,fa,fr,gl,he,hu,it,ja,ka,ko,ms,ne,nl,oc,pt_BR,ro,ru,sk,sl,sv,th,tr,zh_CN,zh_TW}
Language
--advanced, --no-advanced Show advanced options (default disabled)
--interact, --no-interact Interface interaction (default enabled)
--show-intf, --no-show-intf
Show interface with mouse (default disabled)
-I, --intf Interface module
--extraintf Extra interface modules
--control Control interfaces

Hot keys
--key-fullscreen Fullscreen
--key-play-pause Play/Pause
--key-faster Faster
--key-slower Slower
--key-next Next
--key-prev Previous
--key-stop Stop
--key-jump-extrashort
Very short backwards jump
--key-jump+extrashort
Very short forward jump
--key-jump-short Short backwards jump
--key-jump+short Short forward jump
--key-jump-medium
Medium backwards jump
--key-jump+medium
Medium forward jump
--key-jump-long Long backwards jump
--key-jump+long Long forward jump
--key-quit Quit
--key-vol-up Volume up
--key-vol-down Volume down
--key-vol-mute Mute
--key-audio-track
Cycle audio track
--key-subtitle-track
Cycle subtitle track
--key-aspect-ratio
Cycle source aspect ratio
--key-crop Cycle video crop
--key-deinterlace
Cycle deinterlace modes
--extrashort-jump-size
Very short jump length
--short-jump-size
Short jump length
--medium-jump-size
Medium jump length
--long-jump-size Long jump length
--bookmark1 Playlist bookmark 1
--bookmark2 Playlist bookmark 2
--bookmark3 Playlist bookmark 3
--bookmark4 Playlist bookmark 4
--bookmark5 Playlist bookmark 5
--bookmark6 Playlist bookmark 6
--bookmark7 Playlist bookmark 7
--bookmark8 Playlist bookmark 8
--bookmark9 Playlist bookmark 9
--bookmark10 Playlist bookmark 10

Friday, September 14, 2007

Main.java CURRENT


/*
* Main.java
* Created on June 31, 2007, 9:19 PM
*/

package feedme;

import java.awt.Component;
import java.io.*;
import java.nio.*;
import java.util.*;
import javax.script.*;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;

/**
*
* @author john mcloskey
*/
public class Main {

private static Component parent;

/** Creates a new instance of Main */
public Main() {
}

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
/* Which OS are we running on? */
String osName = System.getProperty("os.name");
String libc, libm;
/* JDK1.1 returns "Solaris", 1.2 returns "SunOS". */
if (osName.equals("SunOS") || osName.equals("Solaris")) {
libc = "libc.so";
libm = "libm.so";
} else {
libc = libm = "msvcrt.dll"; // Win32
}
String curDir = System.getProperty("user.dir");
System.out.println(curDir);
ArrayList list = new ArrayList();

list.add( new String(" //////// //////// //////// /////// ") );
list.add( new String(" // // // // // ") );
list.add( new String(" ///// ///// ///// // // ") );
list.add( new String(" // // // // // ") );
list.add( new String(" // //////// //////// /////// ") );
list.add( new String(" ") );
list.add( new String(" /// /// //////// ") );
list.add( new String(" //// //// // ") );
list.add( new String(" // // // // ///// ") );
list.add( new String(" // /// // // ") );
list.add( new String(" // // // //////// ") );
//list.add( new StringBuffer() );

for( String str : list ) {
System.out.println( str );
}

File w = new File("feedme.wip");
// Wed Aug 01 21:21:56 CDT 2007
// Stream to write file feedme.wip
// "crack the wip" file here
FileOutputStream fout;

try {
// Open an output stream
fout = new FileOutputStream("feedme.wip");

// Print a line of text
new PrintStream(fout).println(new Date(Calendar.getInstance().getTimeInMillis()));

// Close our output stream
fout.close();
}
// Catches any error conditions
catch (IOException e) {
System.err.println("Unable to write to wip file");
System.exit(-1);
}
System.out.println("It's now " + new Date(Calendar.getInstance().getTimeInMillis()));
/* JFileChooser
JFileChooser chooser = new JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter(
"AVI video files", "avi");
chooser.setFileFilter(filter);
int returnVal = chooser.showOpenDialog(parent);
if(returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose to open this file: " +
chooser.getSelectedFile().getName());
*/

}

//example jsEngine.eval from javax.script.*
/*ScriptEngineManager mgr = new ScriptEngineManager();
List factories =
mgr.getEngineFactories();
for (ScriptEngineFactory factory: factories) {
System.out.println("ScriptEngineFactory Info");
String engName = factory.getEngineName();
String engVersion = factory.getEngineVersion();
String langName = factory.getLanguageName();
String langVersion = factory.getLanguageVersion();
System.out.printf("\tScript Engine: %s (%s)\n",
engName, engVersion);
List engNames = factory.getNames();
for(String name: engNames) {
System.out.printf("\tEngine Alias: %s\n", name);
}
System.out.printf("\tLanguage: %s (%s)\n",
langName, langVersion);
}
try {
jsEngine.eval("print('Hello, world!')");
} catch (ScriptException ex) {
ex.printStackTrace();
}*/

// August 15, 2007, 7:43 PM - osx out.ipod.mp4 @export method added

/**
* remove the "//" below to @export out.ipod.mp4 to current directory
* in 720x480 wmv media center standard DVD format
*/

// :sout="#transcode{vcodec=mp4v,vb=1024,scale=1, \
// acodec=mp4a,ab=128,channels=2}:standard{access=file, \
// url=out.ipod.mp4}" vlc:quit \
// --aspect-ratio "4:3" --sout-transcode-width 360 \
// --sout-transcode-height 240 --sout-transcode-fps 30

// August 1, 2007, 7:00 PM - linux, osx, and HDDVD output formats added

/**
* remove the "//" below to enable hdiutil out.dvd.dmg @export on osx platform
* updated Wed Aug 04 01:53:00 CDT 2007
*/

// Runtime.getRuntime().exec( "hdiutil create -megabytes 4096 -fs HFS+ \
// -volname FeedMeOutVol out.dvd.dmg" );

/**
* remove the "//" below to enable QTFU6 windows @import method.
* Windows QTFU6 @import method added 08/04/2007.
*/

// Runtime.getRuntime().exec( "C:\Program Files\iTunes\itunes.exe /regserv
// C:\...\QTFairUse\QTFairUse6console.exe --Process all" );

/*
* Linux and BSD @import methods added Wed Aug 04 2007.
*/

/*
* Linux /usr/bin/streamripper @import method.
*/

// Runtime.getRuntime().exec( "/usr/bin/streamripper http://di.fm:8095/");

/*
* BSD /usr/pkg/bin/streamripper @import method.
*/

// Runtime.getRuntime().exec( "/usr/pkg/bin/streamripper http://di.fm:8095/");


//(copy) streams of the following kinds:
//.mp3 Shoutcast streams - the kind of streams found on shoutcast.com.
//.mp3 Icecast streams
//.nvs (Nullsoft Streaming Video) streams
//.aac Shoutcast/Icecast streams
//.ogg stream

/**
* @import in.avi on osx platform
* updated Wed Aug 03 16:53:00 CDT 2007
*/

//Runtime.getRuntime().exec(
// /Applications/VLC.app/Contents/MacOS/VLC -vvv in.avi --sout-ffmpeg-qscale 1

/**
* remove the "//" below to @import in.avi on windows platform
*/

//Runtime.getRuntime().exec(
//"C:\Program Files\VideoLAN\VLC\vlc.exe" -vvv in.avi --sout-ffmpeg-qscale 1

/**
* remove the "//" below to @import in.avi on linux platform
*/

//Runtime.getRuntime().exec(
//"/usr/bin/vlc" -vvv ./in.avi --sout-ffmpeg-qscale 1

/**
* 720x480 wmv media center standard DVD format
*/

//:sout=#transcode{vcodec=WMV2,width=720,height=480,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})

/**
* 1280(width) 720(height) native media center HDDVD 720p format
*/

//:sout=#transcode{vcodec=WMV2,width=1280,height=720,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})


/**
* 1920 (width) x 1080 (height) native media center HDDVD 1080p format
*/

//:sout=#transcode{vcodec=WMV2,width=1920,height=1080,acodec=wma,ab=96,channels=2}
//:duplicate{dst=std{access=file,mux=asf,dst=out.wmv}})
}

}

Sunday, September 9, 2007

AVI Header


// AVI Header
private int usecPerFrame = -1;
private float frameRate = -1.0F;
private int maxBytesPerSecond;
private int paddingGranularity;
private long avgFrameTime;
private int flags = (AVIF_HASINDEX);
private int totalDataLength = 0;
private int totalFrames = 0;
private int totalVideoFrames = 0;
private int initialFrames;
private int[] reserved = new int[4];

private Vector chunkList = new Vector(1);
private final int BUF_SIZE = 16384;
private ByteBuffer bbuf = new ByteBuffer(BUF_SIZE);
private int chunkOffset = 4; // Position of Chunk in file
private int moviOffset = 0;
private int avihOffset = 0;
private int hdrlSizeOffset = 0;
private int totalStrlLength = 0;

private int blockAlign = 1; // todo: when we support multiple audio tracks
// they may have different blockAlign

private int samplesPerBlock = -1; // todo: when we support multiple audio tracks
// they may have different samplesPerBlock

private double sampleRate = 0.; // todo: when we support multiple audio tracks
// they may have different durations

private double audioDuration = 0.; // todo: when we support multiple tracks
// they may have different durations

private int averageBytesPerSecond = -1; // todo: when we support multiple tracks
// they may have different averageBytesPerSecond

private int mp3BitRate = -1; // todo: when we support multiple audio tracks
// they may have different bit rates

private long cumulativeInterFrameTimeVideo = 0;
private long previousTimeStampVideo = 0;
final static String LISTRECORDCHUNK = "rec";
final static String VIDEO_MAGIC = "dc"; // Video
final static String VIDEO_MAGIC_JPEG = "db"; // Video
final static String VIDEO_MAGIC_IV32a = "iv"; // Indeo 3.2
final static String VIDEO_MAGIC_IV32b = "32"; // Indeo 3.2
final static String VIDEO_MAGIC_IV31 = "31"; // Indeo 3.1
final static String VIDEO_MAGIC_CVID = "id"; // Cinepak
final static String AUDIO_MAGIC = "wb"; // Audio

jdk-6u2-ea-bin-b02-linux-i586-12_apr_2007-rpm.bin


# cat /etc/redhat-release
Fedora Core release 6 (Zod)

# wget http://www.java.net/download/jdk6/6u2/promoted/b02/binaries/jdk-6u2-ea-bin-b02-linux-i586-12_apr_2007-rpm.bin

# chmod 755 jdk-6u2-ea-bin-b02-linux-i586-12_apr_2007-rpm.bin

# ./jdk-6u2-ea-bin-b02-linux-i586-12_apr_2007-rpm.bin

Do you agree to the above license terms? [yes or no]
y
Unpacking...
Checksumming...
Extracting...
UnZipSFX 5.50 of 17 February 2002, by Info-ZIP (Zip-Bugs@lists.wku.edu).
inflating: jdk-6u2-ea-linux-i586.rpm
inflating: sun-javadb-common-10.2.2-0.1.i386.rpm
inflating: sun-javadb-core-10.2.2-0.1.i386.rpm
inflating: sun-javadb-client-10.2.2-0.1.i386.rpm
inflating: sun-javadb-demo-10.2.2-0.1.i386.rpm
inflating: sun-javadb-docs-10.2.2-0.1.i386.rpm
inflating: sun-javadb-javadoc-10.2.2-0.1.i386.rpm
Preparing... ########################################### [100%]
1:jdk ########################################### [100%]
Unpacking JAR files...
rt.jar...
jsse.jar...
charsets.jar...
tools.jar...
localedata.jar...
plugin.jar...
javaws.jar...
deploy.jar...
error: %post(jdk-1.6.0_02-ea.i586) scriptlet failed, exit status 5
Installing JavaDB
Preparing... ########################################### [100%]
1:sun-javadb-common ########################################### [ 17%]
2:sun-javadb-core ########################################### [ 33%]
3:sun-javadb-client ########################################### [ 50%]
4:sun-javadb-demo ########################################### [ 67%]
5:sun-javadb-docs ########################################### [ 83%]
6:sun-javadb-javadoc ########################################### [100%]

Done.
# updatedb;locate javac |grep bin
/usr/java/jdk1.6.0_02/bin/javac

# alternatives --install /usr/bin/java java /usr/java/jdk1.6.0_02/bin/java
100

# alternatives --install /usr/bin/jar jar /usr/java/jdk1.6.0_02/bin/jar
100

# alternatives --install /usr/bin/javac javac
/usr/java/jdk1.6.0_02/bin/javac 100

# /usr/sbin/alternatives --config java
java version “1.6.0_02-ea”
Java(TM) SE Runtime Environment (build 1.6.0_02-ea-b02)
Java HotSpot(TM) Client VM (build 1.6.0_02-ea-b02, mixed mode, sharing)

Thursday, September 6, 2007

dispatch.c


Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.

Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
modify and redistribute this software in source and binary code form,
provided that i) this copyright notice and license appear on all copies of
the software; and ii) Licensee does not utilize the software in a manner
which is disparaging to Sun.

This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.

/*
* @(#)dispatch.c 1.9 98/03/22
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* See also the LICENSE file in this distribution.
*/

/*
* JNI native methods supporting the infrastructure for shared
* dispatchers. Includes native methods for classes CPtr, CFunc, and
* CMalloc.
*/

#ifdef SOLARIS2
#include
#define LOAD_LIBRARY(name) dlopen(name, RTLD_LAZY)
#define FIND_ENTRY(lib, name) dlsym(lib, name)
#endif

#ifdef WIN32
#include
#define LOAD_LIBRARY(name) LoadLibrary(name)
#define FIND_ENTRY(lib, name) GetProcAddress(lib, name)
#endif

#include
#include

#include

#include "CPtr.h"
#include "CFunc.h"
#include "CMalloc.h"

/* Global references to frequently used classes and objects */
static jclass classString;
static jclass classInteger;
static jclass classFloat;
static jclass classDouble;
static jclass classCPtr;
static jobject objectCPtrNULL;

/* Cached field and method IDs */
static jmethodID String_getBytes_ID;
static jmethodID String_init_ID;
static jfieldID Integer_value_ID;
static jfieldID Float_value_ID;
static jfieldID Double_value_ID;
static jfieldID CPtr_peer_ID;

/* Forward declarations */
static void throwByName(JNIEnv *env, const char *name, const char *msg);
static char * getJavaString(JNIEnv *env, jstring jstr);
static jstring newJavaString(JNIEnv *env, const char *str);
static jobject makeCPtr(JNIEnv *env, void *p);


/********************************************************************/
/* Native methods of class CFunc */
/********************************************************************/

/* These are the set of types CFunc can handle now */
typedef enum {
TY_CPTR = 0,
TY_INTEGER,
TY_FLOAT,
TY_DOUBLE,
TY_DOUBLE2,
TY_STRING,
} ty_t;

/* represent a machine word */
typedef union {
jint i;
jfloat f;
void *p;
} word_t;

/* A CPU-dependent assembly routine that passes the arguments to C
* stack and invoke the function.
*/
extern void
asm_dispatch(void *func, int nwords, word_t *c_args, ty_t ty, jvalue *resP);

/* invoke the real native function */
static void
dispatch(JNIEnv *env, jobject self, jobjectArray arr, ty_t ty, jvalue *resP)
{
#define MAX_NARGS 32
int i, nargs, nwords;
void *func;
char argTypes[MAX_NARGS];
word_t c_args[MAX_NARGS * 2];

nargs = (*env)->GetArrayLength(env, arr);
if (nargs > MAX_NARGS) {
throwByName(env, "java/lang/IllegalArgumentException",
"too many arguments");
return;
}
func = (void *)(*env)->GetLongField(env, self, CPtr_peer_ID);

for (nwords = 0, i = 0; i < nargs; i++) {
jobject arg = (*env)->GetObjectArrayElement(env, arr, i);
if (arg == NULL) {
throwByName(env, "java/lang/NullPointerException",
"bad argument");
goto cleanup;
}
if ((*env)->IsInstanceOf(env, arg, classInteger)) {
c_args[nwords].i = (*env)->GetIntField(env, arg, Integer_value_ID);
argTypes[nwords++] = TY_INTEGER;
} else if ((*env)->IsInstanceOf(env, arg, classCPtr)) {
c_args[nwords].p =
(void *)(*env)->GetLongField(env, arg, CPtr_peer_ID);
argTypes[nwords++] = TY_CPTR;
} else if ((*env)->IsInstanceOf(env, arg, classString)) {
if ((c_args[nwords].p = getJavaString(env, arg)) == 0) {
goto cleanup;
}
argTypes[nwords++] = TY_STRING;
} else if ((*env)->IsInstanceOf(env, arg, classFloat)) {
c_args[nwords].f = (*env)->GetFloatField(env, arg, Float_value_ID);
argTypes[nwords++] = TY_FLOAT;
} else if ((*env)->IsInstanceOf(env, arg, classDouble)) {
*(jdouble *)(c_args + nwords) =
(*env)->GetDoubleField(env, arg, Double_value_ID);
argTypes[nwords] = TY_DOUBLE;
/* harmless with 64-bit machines*/
argTypes[nwords + 1] = TY_DOUBLE2;
/* make sure things work on 64-bit machines */
nwords += sizeof(jdouble) / sizeof(word_t);
} else {
throwByName(env, "java/lang/IllegalArgumentException",
"unrecognized argument type");
goto cleanup;
}
(*env)->DeleteLocalRef(env, arg);
}

asm_dispatch(func, nwords, c_args, ty, resP);

cleanup:
for (i = 0; i < nwords; i++) {
if (argTypes[i] == TY_STRING) {
free(c_args[i].p);
}
}
return;
}

/*
* Class: CFunc
* Method: callCPtr
* Signature: ([Ljava/lang/Object;)LCPtr;
*/
JNIEXPORT jobject JNICALL
Java_CFunc_callCPtr(JNIEnv *env, jobject self, jobjectArray arr)
{
jvalue result;
dispatch(env, self, arr, TY_CPTR, &result);
if ((*env)->ExceptionOccurred(env)) {
return NULL;
}
return makeCPtr(env, (void *)result.j);
}

/*
* Class: CFunc
* Method: callDouble
* Signature: ([Ljava/lang/Object;)D
*/
JNIEXPORT jdouble JNICALL
Java_CFunc_callDouble(JNIEnv *env, jobject self, jobjectArray arr)
{
jvalue result;
dispatch(env, self, arr, TY_DOUBLE, &result);
return result.d;
}

/*
* Class: CFunc
* Method: callFloat
* Signature: ([Ljava/lang/Object;)F
*/
JNIEXPORT jfloat JNICALL
Java_CFunc_callFloat(JNIEnv *env, jobject self, jobjectArray arr)
{
jvalue result;
dispatch(env, self, arr, TY_FLOAT, &result);
return result.f;
}

/*
* Class: CFunc
* Method: callInt
* Signature: ([Ljava/lang/Object;)I
*/
JNIEXPORT jint JNICALL
Java_CFunc_callInt(JNIEnv *env, jobject self, jobjectArray arr)
{
jvalue result;
dispatch(env, self, arr, TY_INTEGER, &result);
return result.i;
}

/*
* Class: CFunc
* Method: callVoid
* Signature: ([Ljava/lang/Object;)V
*/
JNIEXPORT void JNICALL
Java_CFunc_callVoid(JNIEnv *env, jobject self, jobjectArray arr)
{
jvalue result;
dispatch(env, self, arr, TY_INTEGER, &result);
}

/*
* Class: CFunc
* Method: find
* Signature: (Ljava/lang/String;Ljava/lang/String;)J
*/
JNIEXPORT jlong JNICALL Java_CFunc_find
(JNIEnv *env, jobject self, jstring lib, jstring fun)
{
void *handle;
void *func;
char *libname = 0;
char *funname = 0;

if ((libname = getJavaString(env, lib)) == 0) {
goto ret;
}
if ((funname = getJavaString(env, fun)) == 0) {
goto ret;
}
if ((handle = (void *)LOAD_LIBRARY(libname)) == NULL) {
throwByName(env, "java/lang/UnsatisfiedLinkError", libname);
goto ret;
}
if ((func = (void *)FIND_ENTRY(handle, funname)) == NULL) {
throwByName(env, "java/lang/UnsatisfiedLinkError", funname);
goto ret;
}

ret:
free(libname);
free(funname);
return (jlong)func;
}


/********************************************************************/
/* Native methods of class CPtr */
/********************************************************************/

/*
* Class: CPtr
* Method: initIDs
* Signature: (LCPtr;)I
*/
JNIEXPORT jint JNICALL
Java_CPtr_initIDs(JNIEnv *env, jclass cls, jobject nullCPtr)
{
objectCPtrNULL = (*env)->NewGlobalRef(env, nullCPtr);
if (objectCPtrNULL == NULL) return 0;

classString = (*env)->FindClass(env, "java/lang/String");
if (classString == NULL) return 0;
classString = (*env)->NewGlobalRef(env, classString);
if (classString == NULL) return 0;

classInteger = (*env)->FindClass(env, "java/lang/Integer");
if (classInteger == NULL) return 0;
classInteger = (*env)->NewGlobalRef(env, classInteger);
if (classInteger == NULL) return 0;

classFloat = (*env)->FindClass(env, "java/lang/Float");
if (classFloat == NULL) return 0;
classFloat = (*env)->NewGlobalRef(env, classFloat);
if (classFloat == NULL) return 0;

classDouble = (*env)->FindClass(env, "java/lang/Double");
if (classDouble == NULL) return 0;
classDouble = (*env)->NewGlobalRef(env, classDouble);
if (classDouble == NULL) return 0;

classCPtr = (*env)->NewGlobalRef(env, cls);
if (classCPtr == NULL) return 0;

String_getBytes_ID =
(*env)->GetMethodID(env, classString, "getBytes", "()[B");
if (String_getBytes_ID == NULL) return 0;
String_init_ID = (*env)->GetMethodID(env, classString, "", "([B)V");
if (String_init_ID == NULL) return 0;

Integer_value_ID = (*env)->GetFieldID(env, classInteger, "value", "I");
if (Integer_value_ID == NULL) return 0;

Float_value_ID = (*env)->GetFieldID(env, classFloat, "value", "F");
if (Float_value_ID == NULL) return 0;

Double_value_ID = (*env)->GetFieldID(env, classDouble, "value", "D");
if (Double_value_ID == NULL) return 0;

CPtr_peer_ID = (*env)->GetFieldID(env, classCPtr, "peer", "J");
return sizeof(void *);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[BII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3BII
(JNIEnv *env, jobject self, jint boff, jbyteArray arr, jint off, jint n)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetByteArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[CII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3CII
(JNIEnv *env, jobject self, jint boff, jcharArray arr, jint off, jint n)
{
jchar *peer = (jchar *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetCharArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[DII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3DII
(JNIEnv *env, jobject self, jint boff, jdoubleArray arr, jint off, jint n)
{
jdouble *peer = (jdouble *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetDoubleArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[FII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3FII
(JNIEnv *env, jobject self, jint boff, jfloatArray arr, jint off, jint n)
{
jfloat *peer = (jfloat *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetFloatArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[III)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3III
(JNIEnv *env, jobject self, jint boff, jintArray arr, jint off, jint n)
{
jint *peer = (jint *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetIntArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[JII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3JII
(JNIEnv *env, jobject self, jint boff, jlongArray arr, jint off, jint n)
{
jlong *peer = (jlong *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetLongArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyIn
* Signature: (I[SII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyIn__I_3SII
(JNIEnv *env, jobject self, jint boff, jshortArray arr, jint off, jint n)
{
jshort *peer = (jshort *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->GetShortArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[BII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3BII
(JNIEnv *env, jobject self, jint boff, jbyteArray arr, jint off, jint n)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetByteArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[CII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3CII
(JNIEnv *env, jobject self, jint boff, jcharArray arr, jint off, jint n)
{
jchar *peer = (jchar *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetCharArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[DII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3DII
(JNIEnv *env, jobject self, jint boff, jdoubleArray arr, jint off, jint n)
{
jdouble *peer = (jdouble *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetDoubleArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[FII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3FII
(JNIEnv *env, jobject self, jint boff, jfloatArray arr, jint off, jint n)
{
jfloat *peer = (jfloat *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetFloatArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[III)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3III
(JNIEnv *env, jobject self, jint boff, jintArray arr, jint off, jint n)
{
jint *peer = (jint *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetIntArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[JII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3JII
(JNIEnv *env, jobject self, jint boff, jlongArray arr, jint off, jint n)
{
jlong *peer = (jlong *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetLongArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: copyOut
* Signature: (I[SII)V
*/
JNIEXPORT void JNICALL Java_CPtr_copyOut__I_3SII
(JNIEnv *env, jobject self, jint boff, jshortArray arr, jint off, jint n)
{
jshort *peer = (jshort *)(*env)->GetLongField(env, self, CPtr_peer_ID);
(*env)->SetShortArrayRegion(env, arr, off, n, peer + boff);
}

/*
* Class: CPtr
* Method: getByte
* Signature: (I)B
*/
JNIEXPORT jbyte JNICALL Java_CPtr_getByte
(JNIEnv *env, jobject self, jint index)
{
jbyte res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getCPtr
* Signature: (I)LCPtr;
*/
JNIEXPORT jobject JNICALL Java_CPtr_getCPtr
(JNIEnv *env, jobject self, jint index)
{
void *ptr;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&ptr, peer + index, sizeof(ptr));
return makeCPtr(env, ptr);
}

/*
* Class: CPtr
* Method: getDouble
* Signature: (I)D
*/
JNIEXPORT jdouble JNICALL Java_CPtr_getDouble
(JNIEnv *env, jobject self, jint index)
{
jdouble res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getFloat
* Signature: (I)F
*/
JNIEXPORT jfloat JNICALL Java_CPtr_getFloat
(JNIEnv *env, jobject self, jint index)
{
jfloat res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getInt
* Signature: (I)I
*/
JNIEXPORT jint JNICALL Java_CPtr_getInt
(JNIEnv *env, jobject self, jint index)
{
jint res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getLong
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL Java_CPtr_getLong
(JNIEnv *env, jobject self, jint index)
{
jlong res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getShort
* Signature: (I)S
*/
JNIEXPORT jshort JNICALL Java_CPtr_getShort
(JNIEnv *env, jobject self, jint index)
{
jshort res;
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(&res, peer + index, sizeof(res));
return res;
}

/*
* Class: CPtr
* Method: getString
* Signature: (I)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_CPtr_getString
(JNIEnv *env, jobject self, jint index)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
return newJavaString(env, (const char *)peer + index);
}

/*
* Class: CPtr
* Method: setByte
* Signature: (IB)V
*/
JNIEXPORT void JNICALL Java_CPtr_setByte
(JNIEnv *env, jobject self, jint index, jbyte value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setCPtr
* Signature: (ILCPtr;)V
*/
JNIEXPORT void JNICALL Java_CPtr_setCPtr
(JNIEnv *env, jobject self, jint index, jobject cptr)
{
void *ptr = (void *)(*env)->GetLongField(env, cptr, CPtr_peer_ID);
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &ptr, sizeof(ptr));
}

/*
* Class: CPtr
* Method: setDouble
* Signature: (ID)V
*/
JNIEXPORT void JNICALL Java_CPtr_setDouble
(JNIEnv *env, jobject self, jint index, jdouble value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setFloat
* Signature: (IF)V
*/
JNIEXPORT void JNICALL Java_CPtr_setFloat
(JNIEnv *env, jobject self, jint index, jfloat value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setInt
* Signature: (II)V
*/
JNIEXPORT void JNICALL Java_CPtr_setInt
(JNIEnv *env, jobject self, jint index, jint value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setLong
* Signature: (IJ)V
*/
JNIEXPORT void JNICALL Java_CPtr_setLong
(JNIEnv *env, jobject self, jint index, jlong value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setShort
* Signature: (IS)V
*/
JNIEXPORT void JNICALL Java_CPtr_setShort
(JNIEnv *env, jobject self, jint index, jshort value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
memcpy(peer + index, &value, sizeof(value));
}

/*
* Class: CPtr
* Method: setString
* Signature: (ILjava/lang/String;)V
*/
JNIEXPORT void JNICALL Java_CPtr_setString
(JNIEnv *env, jobject self, jint index, jstring value)
{
jbyte *peer = (jbyte *)(*env)->GetLongField(env, self, CPtr_peer_ID);
char *str = getJavaString(env, value);
if (str == NULL) return;
strcpy((char *)peer + index, str);
free(str);
}


/********************************************************************/
/* Native methods of class CMalloc */
/********************************************************************/

/*
* Class: CMalloc
* Method: malloc
* Signature: (I)J
*/
JNIEXPORT jlong JNICALL Java_CMalloc_malloc
(JNIEnv *env, jclass cls, jint size)
{
return (jlong)malloc(size);
}

/*
* Class: CMalloc
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_CMalloc_free
(JNIEnv *env, jclass cls, jlong ptr)
{
free((void *)ptr);
}


/********************************************************************/
/* Utility functions */
/********************************************************************/

/* Throw an exception by name */
static void
throwByName(JNIEnv *env, const char *name, const char *msg)
{
jclass cls = (*env)->FindClass(env, name);

if (cls != 0) /* Otherwise an exception has already been thrown */
(*env)->ThrowNew(env, cls, msg);

/* It's a good practice to clean up the local references. */
(*env)->DeleteLocalRef(env, cls);
}

/* Translates a Java string to a C string using the String.getBytes
* method, which uses default local encoding.
*/
static char *
getJavaString(JNIEnv *env, jstring jstr)
{
jbyteArray hab = 0;
jthrowable exc;
char *result = 0;

hab = (*env)->CallObjectMethod(env, jstr, String_getBytes_ID);
exc = (*env)->ExceptionOccurred(env);
if (!exc) {
jint len = (*env)->GetArrayLength(env, hab);
result = (char *)malloc(len + 1);
if (result == 0) {
throwByName(env, "java/lang/OutOfMemoryError", 0);
(*env)->DeleteLocalRef(env, hab);
return 0;
}
(*env)->GetByteArrayRegion(env, hab, 0, len, (jbyte *)result);
result[len] = 0; /* NULL-terminate */
} else {
(*env)->DeleteLocalRef(env, exc);
}
(*env)->DeleteLocalRef(env, hab);
return result;
}

/* Constructs a Java string from a C array using the String(byte [])
* constructor, which uses default local encoding.
*/
static jstring
newJavaString(JNIEnv *env, const char *str)
{
jstring result;
jbyteArray hab = 0;
int len;

len = strlen(str);
hab = (*env)->NewByteArray(env, len);
if (hab != 0) {
(*env)->SetByteArrayRegion(env, hab, 0, len, (jbyte *)str);
result = (*env)->NewObject(env, classString,
String_init_ID, hab);
(*env)->DeleteLocalRef(env, hab);
return result;
}
return 0;
}

/* Canonicalize NULL pointers */
static jobject makeCPtr(JNIEnv *env, void *p)
{
jobject obj;
if (p == NULL) {
return objectCPtrNULL;
}
obj = (*env)->AllocObject(env, classCPtr);
if (obj) {
(*env)->SetLongField(env, obj, CPtr_peer_ID, (jlong)p);
}
return obj;
}

JNI's public class Main


Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.

Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
modify and redistribute this software in source and binary code form,
provided that i) this copyright notice and license appear on all copies of
the software; and ii) Licensee does not utilize the software in a manner
which is disparaging to Sun.

This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.

/*
* @(#)Main.java 1.5 98/03/22
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* See also the LICENSE file in this distribution.
*/

/**
* Provides a main() method for running the shared stubs example.
* Shared stubs allow you to call native code (such as the standard C
* library's printf function) from Java code, with very little
* work.
*


* This class uses our prototype implementation of the shared stubs
* distributed with this example.
*
* @author Sheng Liang
* @see CFunc
* @see CPtr
* @see CMalloc
*/
public class Main {

/**
* Demonstrates calling printf, scanf, etc from
* the C library using shared stubs.
*


* Note that this is an example demonstrating the use of shared stubs, and
* must not be construed as us encouraging the use of printf
* from Java code! Infact, we strongly discourage you from doing so ---
* the Java platform APIs provide powerful, type-safe and portable
* alternatives for these C functions, and the Java versions will be a
* performance win. We hope that shared stubs will be useful to you if
* you absolutely must write native methods.
*


* Output from C's printf is enclosed in <>, to distinguish it from things
* we print with System.out.println.
*
* @param main_args Arguments passed from the command line. Currently
* unused.
*/

public static void main(String[] main_args) {

/* Which OS are we running on? */
String osName = System.getProperty("os.name");
String libc, libm;
/* JDK1.1 returns "Solaris", 1.2 returns "SunOS". */
if (osName.equals("SunOS") || osName.equals("Solaris")) {
libc = "libc.so";
libm = "libm.so";
} else {
libc = libm = "msvcrt.dll"; // Win32
}

/* Printing a message with printf(). Note that we first create an
instance of CFunc that wraps around C's printf(). Then we do the
actual call, dispatching to one of the "callXXX" methods on this
instance, based on the return type; in this case it happens to be
callInt. Arguments to the C function are passed as an array of
Objects. Notice we use the "anonymous array creation" syntax for
creating the array of arguments. */
CFunc printf = new CFunc(libc, "printf");
int ires = printf.callInt(new Object[]
{"\n\n", osName});
System.out.println("printf() returned " + ires);


/* Call time() with a NULL pointer. */
CFunc time = new CFunc(libc, "time");
ires = time.callInt(new Object[]{ CPtr.NULL });
System.out.println("\ntime() reports seconds since 1/1/70 as " + ires);


/* Little more complicated. Firstly, ctime() takes a "int *" which
points to an int containing the elapsed seconds since the epoch.
So we will malloc() a 4 byte chunk with C's malloc, and initialize
it the value we just got from time(). Secondly, ctime() returns a
string, so be aware of that. */
CMalloc timePtr = new CMalloc(4);
timePtr.setInt(0, ires);
CFunc ctime = new CFunc(libc, "ctime");
CPtr returnedString = ctime.callCPtr(new Object[]{ timePtr });
System.out.print("\nctime() reports " + returnedString.getString(0));
/* We malloc()ed something from C heap, so we have to free() it. */
timePtr.free();


/* Read first word from stdin with scanf(). */
System.out.println("\nPlease type something and then hit ");
CFunc scanf = new CFunc(libc, "scanf");
CMalloc cbuf = new CMalloc(128);
ires = scanf.callInt(new Object[]{ "%s", cbuf });
System.out.println("scanf() says first word you typed is \"" +
cbuf.getString(0) + "\"");
/* malloc()ed memory must be freed! */
cbuf.free();


/* Caculate C's sin(2.0) with Math.sin(2.0). */
CFunc sin = new CFunc(libm, "sin");
double dres = sin.callDouble(new Object[]{new Double(2.0) });
System.out.println("\nC's sin(2.0) = " + dres);
System.out.println("Math.sin(2.0) = " + Math.sin(2.0));


/* clock(). Takes no arguments. */
CFunc clock = new CFunc(libc, "clock");
System.out.println("\nclock() returned " +
clock.callInt(new Object[0]));
}
}

CPtr.java


Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.

Sun grants you ("Licensee") a non-exclusive, royalty free, license to use,
modify and redistribute this software in source and binary code form,
provided that i) this copyright notice and license appear on all copies of
the software; and ii) Licensee does not utilize the software in a manner
which is disparaging to Sun.

This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

This software is not designed or intended for use in on-line control of
aircraft, air traffic, aircraft navigation or aircraft communications; or in
the design, construction, operation or maintenance of any nuclear
facility. Licensee represents and warrants that it will not use or
redistribute the Software for such purposes.
/*
* @(#)CPtr.java 1.8 98/03/22
*
* Copyright (c) 1998 Sun Microsystems, Inc. All Rights Reserved.
*
* See also the LICENSE file in this distribution.
*/

/**
* An abstraction for a C pointer data type. A CPtr instance represents, on
* the Java side, a C pointer. The C pointer could be any type of C
* pointer. Methods such as copyIn, copyOut,
* getXXX, and setXXX, provide
* means to indirect the underlying C pointer.
*
* @author Sheng Liang
* @see CFunc
*/
public class CPtr {

/**
* The size of a C pointer on the platform this Java virtual machine is
* running on.
*/
public static final int SIZE;

/**
* A canonical representation of C's NULL pointer.
*/
public static final CPtr NULL;


/**
* Compares this CPtr to the specified object.
*
* @param other a CPtr
* @return true if the class of this CPtr object and the
* class of other are exactly equal, and the C
* pointers being pointed to by these objects are also
* equal. Returns false otherwise.
*/
public boolean equals(Object other) {
if (other == null)
return false;
if (other == this)
return true;
if (CPtr.class != other.getClass())
return false;
return peer == ((CPtr)other).peer;
}

/**
* Returns a hashcode for the C pointer represented by this
* Cptr object.
*
* @return a hash code value for the represented C pointer.
*/
public int hashCode() {
return (int)((peer >>> 32) + (peer & 0xFFFFFFFF));
}

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf byte array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, byte[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf short array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, short[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf char array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, char[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf int array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, int[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf long array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, long[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf float array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, float[] buf, int index, int length);

/**
* Indirect the C pointer, copying into memory pointed to by C
* pointer, from the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf double array from which to copy
* @param index array index from which to start copying
* @param length number of elements from buf that must be
* copied
*/
public native void copyIn(int bOff, double[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer into which data is copied
* @param buf byte array into which data is copied
* @param index array index from which to start copying
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, byte[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf short array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, short[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf char array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, char[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf int array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, int[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf long array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, long[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf float array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, float[] buf, int index, int length);

/**
* Indirect the C pointer, copying from memory pointed to by C
* pointer, into the specified array.
*
* @param bOff byte offset from pointer from which data is copied
* @param buf double array into which data is copied
* @param index array index to which data is copied
* @param length number of elements from C pointer that must be copied
*/
public native void copyOut(int bOff, double[] buf, int index, int length);

/**
* Indirect the C pointer as a pointer to byte. This is
* equivalent to the expression
* *((jbyte *)((char *)cptr + * offset)).
*
* @param offset offset from pointer to perform the indirection
* @return the byte value being pointed to
*/
public native byte getByte(int offset);

/**
* Indirect the C pointer as a pointer to short. This is
* equivalent to the expression
* *((jshort *)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the short value being pointed to
*/
public native short getShort(int offset);

/**
* Indirect the C pointer as a pointer to int. This is
* equivalent to the expression
* *((jint *)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the int value being pointed to
*/
public native int getInt(int offset);

/**
* Indirect the C pointer as a pointer to long. This is
* equivalent to the expression
* *((jlong *)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the long value being pointed to
*/
public native long getLong(int offset);

/**
* Indirect the C pointer as a pointer to float. This is
* equivalent to the expression
* *((jfloat *)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the float value being pointed to
*/
public native float getFloat(int offset);

/**
* Indirect the C pointer as a pointer to double. This is
* equivalent to the expression
* *((jdouble *)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the double value being pointed to
*/
public native double getDouble(int offset);

/**
* Indirect the C pointer as a pointer to pointer. This is equivalent to
* the expression *((void **)((char *)cptr + offset)).
*
* @param offset byte offset from pointer to perform the indirection
* @return the pointer value being pointed to
*/
public native CPtr getCPtr(int offset);

/**
* Indirect the C pointer as a pointer to char *, a
* NULL-terminated C string. Convert the C string to a
* java.lang.String.
*
* @param offset byte offset from pointer to obtain the C string
* @return the String value being pointed to
*/
public native String getString(int offset);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jbyte *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value byte value to set
*/
public native void setByte(int offset, byte value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jshort *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value short value to set
*/
public native void setShort(int offset, short value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jint *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value int value to set
*/
public native void setInt(int offset, int value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jlong *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value long value to set
*/
public native void setLong(int offset, long value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jfloat *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value float value to set
*/
public native void setFloat(int offset, float value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression
* *((jdouble *)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value double value to set
*/
public native void setDouble(int offset, double value);

/**
* Set value at location being pointed to. This is equivalent
* to the expression *((void **)((char *)cptr + offset)) = value.
*
* @param offset byte offset from pointer at which value
* must be set
* @param value CPtr value to set
*/
public native void setCPtr(int offset, CPtr value);

/**
* Copy string value to the location being pointed to. Copy
* each element in value, converted to native encoding, at an
* offsetfrom the location pointed to by this pointer.
*
* @param offset byte offset from pointer at which characters in
* value must be set
* @param value java.lang.String value to set
*/
public native void setString(int offset, String value);

/* Initialize field and method IDs for native methods of this class. */
private static native int initIDs(CPtr p);

static {
System.loadLibrary("disp");
NULL = new CPtr();
SIZE = initIDs(NULL);
}

/* peer and the no-args constructor are deliberately package private, so
all classes that are abstractions of a C pointer will can only be in
one isolated package. */

/* Pointer value of the real C pointer. Use long to be 64-bit safe. */
long peer;

/* No-args constructor, see comment above. */
CPtr() {}

}