亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? rawdatasourcehandler.java

?? 是一個用java實現的
?? JAVA
字號:
/*
 * RawDataSourceHandler.java
 * 
 * Created on Mar 16, 2004
 *
 */
package gov.nist.applet.phone.media.messaging;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Vector;

import javax.media.Buffer;
import javax.media.DataSink;
import javax.media.IncompatibleSourceException;
import javax.media.MediaLocator;
import javax.media.datasink.DataSinkErrorEvent;
import javax.media.datasink.DataSinkEvent;
import javax.media.datasink.DataSinkListener;
import javax.media.datasink.EndOfStreamEvent;
import javax.media.protocol.BufferTransferHandler;
import javax.media.protocol.PullBufferDataSource;
import javax.media.protocol.PullBufferStream;
import javax.media.protocol.PushBufferDataSource;
import javax.media.protocol.PushBufferStream;
import javax.media.protocol.SourceStream;

import javax.media.protocol.DataSource;

/**
 * This Data source Handler allow one to write directly from a DataSource 
 * to an array of byte.
 * This Data Source Handler allow one to fill a buffer with MPEG_AUDIO 
 * or GSM audio data.
 * Example : One can record his voice from a microphone to a buffer in either a
 * MP3 or GSM format. To get the buffer with the recorded voice just call the
 * getRecordBuffer method
 *
 * @author Jean Deruelle <jean.deruelle@nist.gov>
 *
 * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
 */
public class RawDataSourceHandler implements DataSink, BufferTransferHandler{
	public static final int NUMBER_OF_BYTES_FOR_ONE_SECOND=18928;
	DataSource source;
	PullBufferStream pullStrms[] = null;
	PushBufferStream pushStrms[] = null;
	//length of the buffer read
	int bufferLengthRead=0;
	//length of the buffer read
	int bufferLength=0;
	
	// Data sink listeners.
	private Vector listeners = new Vector(1);

	// Stored all the streams that are not yet finished (i.e. EOM
	// has not been received.
	SourceStream unfinishedStrms[] = null;

	// Loop threads to pull data from a PullBufferDataSource.
	// There is one thread per each PullSourceStream.
	Loop loops[] = null;

	Buffer readBuffer;
	ByteArrayOutputStream baout=null;
	
	/**
	 * Default Constructor
	 */
	public RawDataSourceHandler(){
		baout=new ByteArrayOutputStream();
	}
	
	/**
	 * 
	 * @param duration - duration to buffer in sec
	 */
	public RawDataSourceHandler(int duration){
		bufferLength=duration*NUMBER_OF_BYTES_FOR_ONE_SECOND;		
		baout=new ByteArrayOutputStream(bufferLength);
	}


	/**
     * Set the data source of this data source handler
     * @exception IncompatibleSourceException - if the data source cannot be 
     * handled, this exception is thrown
     */
	public void setSource(DataSource source) throws IncompatibleSourceException {
		//System.out.println(source.getClass().getName());
	    // Different types of DataSources need to handled differently.
	    if (source instanceof PushBufferDataSource) {

			pushStrms = ((PushBufferDataSource)source).getStreams();
			unfinishedStrms = new SourceStream[pushStrms.length];
	
			// Set the transfer handler to receive pushed data from
			// the push DataSource.
			for (int i = 0; i < pushStrms.length; i++) {
			    pushStrms[i].setTransferHandler(this);
			    unfinishedStrms[i] = pushStrms[i];
			}


	    } else if (source instanceof PullBufferDataSource) {

			pullStrms = ((PullBufferDataSource)source).getStreams();
			unfinishedStrms = new SourceStream[pullStrms.length];
	
			// For pull data sources, we'll start a thread per
			// stream to pull data from the source.
			loops = new Loop[pullStrms.length];
			for (int i = 0; i < pullStrms.length; i++) {
			    loops[i] = new Loop(this, pullStrms[i]);
			    unfinishedStrms[i] = pullStrms[i];
			}

	    } else {

			// This handler only handles push or pull buffer datasource.
			throw new IncompatibleSourceException();

	    }

	    this.source = source;
	    readBuffer = new Buffer();
	}


	/**
	 * For completeness, DataSink's require this method.
	 * But we don't need it.
	 */
	public void setOutputLocator(MediaLocator ml) {
	}

	/**
	 * For completeness, DataSink's require this method.
	 * But we don't need it.
	 */
	public MediaLocator getOutputLocator() {
	    return null;
	}

	/**
	 * Get the current content type for this data source handler
	 *
	 * @return The current <CODE>ContentDescriptor</CODE> for this data source handler.
	 */
	public String getContentType() {
	    return source.getContentType();
	}


	/**
	 * Our DataSink does not need to be opened.
	 */
	public void open() {
	}

	/**
	 * @see javax.media.DataSink#start()
	 */
	public void start() {
	    try {
			source.start();
	    } catch (IOException e) {
			System.err.println(e);
	    }

	    // Start the processing loop if we are dealing with a
	    // PullBufferDataSource.
	    if (loops != null) {
			for (int i = 0; i < loops.length; i++)
			    loops[i].restart();
	    }
	}

	/**
	 * @see javax.media.DataSink#stop()
	 */
	public void stop() {
	    try {
			source.stop();
	    } catch (IOException e) {
			System.err.println(e);
	    }

	    // Start the processing loop if we are dealing with a
	    // PullBufferDataSource.
	    if (loops != null) {
			for (int i = 0; i < loops.length; i++)
			    loops[i].pause();
	    }
	}

	/**
	 * @see javax.media.DataSink#close()
	 */
	public void close() {
	    stop();
	    if (loops != null) {
			for (int i = 0; i < loops.length; i++)
			    loops[i].kill();
	    }	
		System.out.println(bufferLengthRead+" bytes have been read");
		System.out.println("nb bytes actually in the buffer: "+baout.size());	
		//writeBufferToFile("d://temp//data.txt");  
	}

	/**
	 * @see javax.media.DataSink#addDataSinkListener(javax.media.datasink.DataSinkListener)
	 */
	public void addDataSinkListener(DataSinkListener dsl) {
	    if (dsl != null)
		if (!listeners.contains(dsl))
		    listeners.addElement(dsl);
	}

	/**
	 * @see javax.media.DataSink#removeDataSinkListener(javax.media.datasink.DataSinkListener)
	 */
	public void removeDataSinkListener(DataSinkListener dsl) {
	    if (dsl != null)
		listeners.removeElement(dsl);
	}

	/**
	 * Send event to the listeners
	 * @param event - the vent to send
	 */
	protected void sendEvent(DataSinkEvent event) {
	    if (!listeners.isEmpty()) {
		synchronized (listeners) {
		    Enumeration list = listeners.elements();
		    while (list.hasMoreElements()) {
			DataSinkListener listener = 
				(DataSinkListener)list.nextElement();
			listener.dataSinkUpdate(event);
		    }
		}
	    }
	}

	/**
	 * This will get called when there's data pushed from the
	 * PushBufferDataSource.
	 * @param stream - stream from which the data are transferred
	 */
	public void transferData(PushBufferStream stream) {
		//System.out.println("push");
	    try {
			stream.read(readBuffer);
	    } catch (IOException e) {
			System.err.println(e);
			sendEvent(new DataSinkErrorEvent(this, e.getMessage()));
			return;
	    }

	    bufferData(readBuffer);

	    // Check to see if we are done with all the streams.
	    if (readBuffer.isEOM() && checkDone(stream)) {
			sendEvent(new EndOfStreamEvent(this));
	    }
	}


	/**
	 * This is called from the Loop thread to pull data from
	 * the PullBufferStream.
	 * @param stream - stream from which the data are pulled
	 */
	public boolean readPullData(PullBufferStream stream) {
		//System.out.println("pull");
	    try {
			stream.read(readBuffer);
	    } catch (IOException e) {			
			System.err.println(e);
			return true;
	    }

	    bufferData(readBuffer);

	    if (readBuffer.isEOM()) {
	        // Check to see if we are done with all the streams.
		if (checkDone(stream)) {
		    System.err.println("All done!");
		    close();
		}
		return true;
	    }
	    return false;
	}


	/**
	 * Check to see if all the streams are processed.
	 * @param strm - the stream to check
	 */
	public boolean checkDone(SourceStream strm) {
	    boolean done = true;

	    for (int i = 0; i < unfinishedStrms.length; i++) {
		if (strm == unfinishedStrms[i])
		    unfinishedStrms[i] = null;
		else if (unfinishedStrms[i] != null) {
		    // There's at least one stream that's not done.
		    done = false;
		}
	    }
	    return done;
	}

	/**
	 * Buffer the data given by the buffer in parameter in our data source handler
	 * buffer
	 * @param buffer - the buffer that provide data
	 */
	void bufferData(Buffer buffer) {
	    //System.err.println("Read from stream: " + stream);
	    /*if (buffer.getFormat() instanceof AudioFormat){
			System.err.println("Read audio data: "+buffer.getFormat());
	    }
	    else
			System.err.println("Read video data:");
	    System.err.println("  Time stamp: " + buffer.getTimeStamp());
	    System.err.println("  Sequence #: " + buffer.getSequenceNumber());
	    System.err.println("  Data length: " + buffer.getLength());*/
		Object data=buffer.getData();
		if(data instanceof byte[]){			
			byte[] audioData=(byte[])data;
			bufferLengthRead+=audioData.length;
			try{
				baout.write(audioData);
			}
			catch(IOException ioe){
				ioe.printStackTrace();
			}
		}		
			
	    if (buffer.isEOM())
			System.err.println("  Got EOM!");
	}
	/**
	 * Obtain the collection of objects that
	 * control the object that implements this interface.
	 * <p>
	 *
	 * No controls are supported.
	 * A zero length array is returned.
	 *
	 * @return A zero length array
	 */
	public Object [] getControls() {
	    return new Object[0];
	}
	/**
	 * Obtain the object that implements the specified
	 * <code>Class</code> or <code>Interface</code>
	 * The full class or interface name must be used.
	 * <p>
	 *
	 * The control is not supported.
	 * <code>null</code> is returned.
	 *
	 * @return <code>null</code>.
	 */
	public Object getControl(String name) {
	    return null;
	}
	/**
	 * Get the recorded buffer of this data source handler
	 * @return byte array containing the data recorded
	 */
	public byte[] getRecordBuffer(){
		return baout.toByteArray();
	}
	/**
	 * Utility method to write the data source handler buffer to a file
	 * @param fileName - the file where to write the buffer
	 */
	public void writeBufferToFile(String fileName){
		File f=new File(fileName);
		FileOutputStream fos=null;
		try{
			fos=new FileOutputStream(fileName);
		}
		catch(FileNotFoundException fnfe){
			fnfe.printStackTrace();
		}
		try{
			fos.write(baout.toByteArray());
		}
		catch(IOException ioe){
			ioe.printStackTrace();
		}
	}
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
天天色天天操综合| 综合欧美一区二区三区| 亚洲一区在线观看视频| 在线视频你懂得一区| 亚洲综合小说图片| 7777精品伊人久久久大香线蕉| 亚洲成人中文在线| 在线不卡一区二区| 国产又黄又大久久| 国产视频一区在线观看| 91网上在线视频| 亚洲成人动漫在线观看| 日韩欧美一二三区| 成人h动漫精品一区二区| 亚洲免费观看高清完整版在线观看| 欧美在线一二三| 老汉av免费一区二区三区| 久久女同精品一区二区| 91丨porny丨中文| 日本一区中文字幕| 欧美韩日一区二区三区四区| 91黄色激情网站| 久久成人久久鬼色| 日韩理论片在线| 亚洲欧洲综合另类在线| 欧美日韩国产系列| 成人一级视频在线观看| 亚洲国产美女搞黄色| 久久伊人蜜桃av一区二区| 91首页免费视频| 久久99精品一区二区三区三区| 欧美激情自拍偷拍| 7777精品伊人久久久大香线蕉| 国产成人av一区| 婷婷六月综合亚洲| 国产精品久久久久久亚洲毛片 | 91精品国产欧美一区二区成人| 久久电影网站中文字幕 | 亚洲综合免费观看高清完整版在线| 在线播放欧美女士性生活| 国产成人精品www牛牛影视| 天堂久久久久va久久久久| 日本一区二区三区电影| 91麻豆精品久久久久蜜臀 | 欧美午夜精品电影| 国产大片一区二区| 天堂成人国产精品一区| 亚洲欧洲99久久| 久久午夜色播影院免费高清 | proumb性欧美在线观看| 蜜桃精品在线观看| 一区二区三区在线视频观看58| 久久在线免费观看| 这里是久久伊人| 欧美三片在线视频观看| 97久久精品人人澡人人爽| 狠狠色丁香久久婷婷综合_中| 亚洲1区2区3区4区| 亚洲欧美激情插| 成人免费一区二区三区视频| 国产女同性恋一区二区| 久久综合久色欧美综合狠狠| 欧美一级午夜免费电影| 欧美日韩一级大片网址| 一本色道久久综合亚洲91| 成人免费看的视频| 丁香六月久久综合狠狠色| 国产在线播精品第三| 国产一区二区三区四| 裸体歌舞表演一区二区| 蜜臀va亚洲va欧美va天堂| 性欧美疯狂xxxxbbbb| 亚洲午夜在线观看视频在线| 亚洲免费成人av| 亚洲欧洲综合另类在线| 亚洲精品五月天| 亚洲女厕所小便bbb| 最新中文字幕一区二区三区 | 欧美日韩国产高清一区二区三区| 色综合一区二区| 91免费视频网址| 91久久奴性调教| 欧美自拍偷拍午夜视频| 欧美性一二三区| 欧美三电影在线| 欧美日韩精品三区| 欧美一区二区三区四区视频| 91麻豆精品国产91久久久久| 日韩亚洲欧美在线| 精品国产乱码久久久久久浪潮| 久久综合视频网| 欧美国产日本视频| 亚洲日本成人在线观看| 亚洲综合久久av| 日韩制服丝袜先锋影音| 久99久精品视频免费观看| 国产一区二区三区四区五区入口| 国产成人av电影在线观看| 成人av在线看| 欧美日韩一区二区欧美激情| 日韩欧美在线网站| 欧美国产视频在线| 亚洲精品国久久99热| 日欧美一区二区| 国产乱理伦片在线观看夜一区 | 在线观看视频一区| 91精品免费在线观看| 国产日韩高清在线| 亚洲欧美激情插 | 中文字幕一区二区三区不卡| 国产精品久久网站| 亚洲成av人片在线| 最新中文字幕一区二区三区 | 麻豆久久一区二区| 国产成人综合视频| 色狠狠av一区二区三区| 日韩欧美你懂的| 自拍偷自拍亚洲精品播放| 日韩成人一区二区三区在线观看| 国产美女精品在线| 欧美性猛片aaaaaaa做受| 日韩精品一区二区三区视频播放| 国产精品美女久久久久久久久久久| 亚洲综合成人在线视频| 韩国毛片一区二区三区| 在线视频综合导航| 久久久久综合网| 亚洲高清不卡在线观看| 国产不卡视频在线播放| 91麻豆精品国产无毒不卡在线观看| 中文字幕精品一区二区精品绿巨人| 亚洲午夜视频在线| 国产91精品免费| 日韩一区二区麻豆国产| 一区二区在线观看av| 国产精品一区二区三区乱码| 九九视频精品免费| 亚洲婷婷在线视频| 蜜桃视频第一区免费观看| 91丝袜呻吟高潮美腿白嫩在线观看| 日韩丝袜美女视频| 亚洲一区日韩精品中文字幕| 国产在线播放一区三区四| 91精品国产入口| 亚洲综合一区二区三区| 99久久亚洲一区二区三区青草| 久久影院午夜论| 欧美a一区二区| 欧美电影一区二区| 一区二区三区精品| 97国产一区二区| 中文字幕免费观看一区| 久久成人18免费观看| 欧美一区二区在线免费播放| 亚洲电影你懂得| 欧美性大战久久| 一区二区三区四区国产精品| 成人av在线看| ●精品国产综合乱码久久久久 | 成人一区二区三区| 国产亚洲人成网站| 国产精品 日产精品 欧美精品| 欧美电视剧在线观看完整版| 日韩成人免费电影| 日本不卡中文字幕| 久久 天天综合| 日韩欧美在线观看一区二区三区| 午夜成人免费电影| 777午夜精品视频在线播放| 亚洲成人精品在线观看| 91福利精品第一导航| 亚洲综合男人的天堂| 欧美日韩高清不卡| 日本欧美久久久久免费播放网| 91精品国产综合久久蜜臀| 青青草一区二区三区| 日韩欧美在线网站| 国产一二精品视频| 亚洲国产成人在线| 色哟哟在线观看一区二区三区| 一区二区视频免费在线观看| 欧美日韩在线直播| 人人狠狠综合久久亚洲| 26uuu亚洲综合色| 国产福利不卡视频| 亚洲天堂2014| 欧美日韩一区二区三区在线| 青青草97国产精品免费观看 | 欧美高清www午色夜在线视频| 天堂在线一区二区| 91精品国产高清一区二区三区| 看片的网站亚洲| 91精品国产综合久久小美女| 日韩av电影天堂| 久久综合色8888| 91麻豆福利精品推荐| 日韩一区精品视频| 久久久国际精品| 欧美日韩一区二区在线观看视频 | 久久99精品久久久久婷婷|