Java 8 Line - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 Line class.

This code example shows how to use the following methods:flush, stop, close
     * Stop wav play back 
     *  
     */ 
    public static void stopWavFile() 
    { 
    	m_clip.stop();
    	m_clip.flush();
    	m_clip.close();  	
    } 
 
    public static double[] getSamplesAsDoubleArray(AudioInputStream ais) {
        return new AudioDoubleDataSource(ais).getAllData();
    } 
     
    public static void writeWavFile(double[] x, String outputFile, AudioFormat format) throws IOException
    { 
        DDSAudioInputStream outputAudio = new DDSAudioInputStream(new BufferedDoubleDataSource(x), format);
 
        AudioSystem.write(outputAudio, AudioFileFormat.Type.WAVE, new File(outputFile));
    } 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:open, drain, addLineListener, close
            AudioFormat format = audioInputStream.getFormat();
            DataLine.Info   info = new DataLine.Info(Clip.class, format,
                                             AudioSystem.NOT_SPECIFIED);
            try { 
                audioClip = (Clip) AudioSystem.getLine(info);
                audioClip.addLineListener(this);
                audioClip.open(audioInputStream);
            } catch (LineUnavailableException e) {
                project.log("The sound device is currently unavailable");
                return; 
            } catch (IOException e) {
                e.printStackTrace();
            } 
 
            if (duration != null) {
                playClip(audioClip, duration.longValue());
            } else { 
                playClip(audioClip, loops);
            } 
            audioClip.drain();

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:start, stop, close, open
		/* Starting the TargetDataLine. It tells the line that 
		   we now want to read data from it. If this method 
		   isn't called, we won't 
		   be able to read data from the line at all. 
		*/ 
		m_line.start();
 
		/* Starting the thread. This call results in the 
		   method 'run()' (see below) being called. There, the 
		   data is actually read from the line. 
		*/ 
		super.start(); 
	} 
 
 
	/** Stops the recording. 
 
	    Note that stopping the thread explicitely is not necessary. Once 
	    no more data can be read from the TargetDataLine, no more data 
	    be read from our AudioInputStream. And if there is no more 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:start, stop, close, open
		/* Starting the TargetDataLine. It tells the line that 
		   we now want to read data from it. If this method 
		   isn't called, we won't 
		   be able to read data from the line at all. 
		*/ 
		m_line.start();
 
		/* Starting the thread. This call results in the 
		   method 'run()' (see below) being called. There, the 
		   data is actually read from the line. 
		*/ 
		super.start(); 
	} 
 
 
	/** Stops the recording. 
 
	    Note that stopping the thread explicitely is not necessary. Once 
	    no more data can be read from the TargetDataLine, no more data 
	    be read from our AudioInputStream. And if there is no more 

6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:close
		for (int i = 0, j = 0; i < numSamples * 2; i += 2, j++)
			samples[offset + j] = (short)((buffer[i + 1] << 8) | (buffer[i] & 0xff));
	} 
 
	public void dispose () { 
		line.close();
	} 
} 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:drain, flush, close
 
    public void close() 
    { 
        try 
        { 
            this.clip.drain();
            this.clip.flush();
            this.clip.close();
        } 
        catch (Exception e)
        { 
            LogUtil.put(LogFactory.getInstance( 
                "Exception", this, "close", e));
        } 
    } 
 
    public String getContentType()
    { 
        return null; 
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:drain, flush, close
 
    public void close() 
    { 
        try 
        { 
            this.clip.drain();
            this.clip.flush();
            this.clip.close();
        } 
        catch (Exception e)
        { 
            LogUtil.put(LogFactory.getInstance( 
                "Exception", this, "close", e));
        } 
    } 
 
    public String getContentType()
    { 
        return null; 
    } 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:getBufferSize, getControl, isControlSupported, open
        DataLine.Info info = new DataLine.Info(SourceDataLine.class,
                audioFormat, AudioSystem.NOT_SPECIFIED);
        SourceDataLine line = (SourceDataLine) AudioSystem.getLine(info);
 
        if (bufferSize <= 0)
            bufferSize = line.getBufferSize();
        line.open(audioFormat, bufferSize);
 
        /*-- Is Gain Control supported ? --*/ 
        if (line.isControlSupported(FloatControl.Type.MASTER_GAIN)) {
            gainControl = (FloatControl) line
                    .getControl(FloatControl.Type.MASTER_GAIN);
        } 
        return line;
    } 
 
    /** 
     * Creates a map of properties about the current inputstream. Unlike many inputStreams, 
     * audioInputStreams have a variety of extra properties associated with them such as 
     * <pre> 
6
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:stop, close
     * It's not a good idea to call this method just 'stop()' because stop() is 
     * a (deprecated) method of the class 'Thread'. And we don't want to 
     * override this method. 
     */ 
    public void stopRecording() { 
        m_line.stop();
        m_line.close();
    } 
 
    /** 
     * Main working method. You may be surprised that here, just 
     * 'AudioSystem.write()' is called. But internally, it works like this: 
     * AudioSystem.write() contains a loop that is trying to read from the 
     * passed AudioInputStream. Since we have a special AudioInputStream that 
     * gets its data from a TargetDataLine, reading from the AudioInputStream 
     * leads to reading from the TargetDataLine. The data read this way is then 
     * written to the passed File. Before writing of audio data starts, a header 
     * is written according to the desired audio file type. Reading continues 
     * untill no more data can be read from the AudioInputStream. In our case, 
     * this happens if no more data can be read from the TargetDataLine. This, 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:stop, close
     * It's not a good idea to call this method just 'stop()' because stop() is 
     * a (deprecated) method of the class 'Thread'. And we don't want to 
     * override this method. 
     */ 
    public void stopRecording() { 
        m_line.stop();
        m_line.close();
    } 
 
    /** 
     * Main working method. You may be surprised that here, just 
     * 'AudioSystem.write()' is called. But internally, it works like this: 
     * AudioSystem.write() contains a loop that is trying to read from the 
     * passed AudioInputStream. Since we have a special AudioInputStream that 
     * gets its data from a TargetDataLine, reading from the AudioInputStream 
     * leads to reading from the TargetDataLine. The data read this way is then 
     * written to the passed File. Before writing of audio data starts, a header 
     * is written according to the desired audio file type. Reading continues 
     * untill no more data can be read from the AudioInputStream. In our case, 
     * this happens if no more data can be read from the TargetDataLine. This, 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Java 8 Line Methods: