Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / September 2007

Tip: Looking for answers? Try searching our database.

Methods which return 'abstract'

Thread view: 
ChrisW - 04 Sep 2007 18:26 GMT
Hi,

I'm trying to use Java Sound to write a new .wav file, so am using
AudioFileWriter, for which the API contains the following information:

public abstract int write(AudioInputStream stream,
AudioFileFormat.Type fileType, OutputStream out)
                  throws IOException

I don't quite understand how to use this method since I don't
understand what the 'abstract' keyword means.  I've looked at the
AudioConcat.java class (and associated SequenceAudioInputStream.java)
from jsresources.org, and tried to write my own class using this
example.  The code I've got so far is:

public class makeSound {

       private List m_audioInputStreamList;
    private    int m_nCurrentStream;

    public void SequenceAudioInputStream(AudioFormat audioFormat, List
audioInputStreams)

    {
        super(new ByteArrayInputStream(new byte[0]), audioFormat,
AudioSystem.NOT_SPECIFIED);
        m_audioInputStreamList = new ArrayList(audioInputStreams);
        m_nCurrentStream = 0;
    }

      public static void main(String[] args) throws
UnsupportedAudioFileException, IOException {

        try {

            AudioInputStream ais1 = null;
                       AudioInputStream ais2 = null;

            File file1 = new File("1.wav");
            File file2 = new File("2.wav");

            AudioFileFormat    aff1 = AudioSystem.getAudioFileFormat(file1);
            AudioFileFormat    aff2 = AudioSystem.getAudioFileFormat(file2);

            ais1 = AudioSystem.getAudioInputStream(file1);
            ais2 = AudioSystem.getAudioInputStream(file2);

            List <AudioInputStream> audioInputStreamList = new ArrayList
<AudioInputStream> ();

            audioInputStreamList.add(ais1);

                       //I hope, that by this point, my List will
contain the Stream of the 1st file

                       //AudioInputStream audioInputStream =
SequenceAudioInputStream(AudioFileFormat.Type.WAVE,
audioInputStreamList);

                       //File outputFile = new File("Final.wav");
            //AudioSystem.write(audioInputStream, AudioFileFormat.Type.WAVE,
outputFile);

        }

        catch (UnsupportedAudioFileException e) {

            System.out.println(e);
        }

        catch (IOException ioe) {

            System.out.println(ioe);
        }

    }

/*
    private static File newFile(AudioInputStream currentFileIS, File
completedFile) throws IOException {

           File completedFile = new File("Final.wav");
        AudioSystem.write(currentFileIS, AudioFileFormat.Type.WAVE,
completedFile);
        return AudioSystem;

    }
*/

}

I hope that what I am trying to do is relatively obvious. However,
once I've added elements to my List I'm completely lost as to what to
do next - my SequenceAudioInputStream doesn't work and I don't know
what to do to make it work! I know I need to convert my List into an
AudioInputStream.  I can't use the program from jsresource as is, as I
need a blank, fixed length audio file onto which I need to put/mix at
fixed intervals the 2 audio files (file1 and file2) (- something I
still need to work out how to do!).

If anyone can point me in the right direction, I'd be most grateful.

Chris
Hunter Gratzner - 04 Sep 2007 19:40 GMT
> I don't quite understand how to use this method since I don't
> understand what the 'abstract' keyword means.

Read this http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html
or som Java textbook.
Lew - 04 Sep 2007 23:10 GMT
ChrisW <c.c.w...@gmail.com> wrote:
>> I don't quite understand how to use this method since I don't
>> understand what the 'abstract' keyword means.

A method doesn't "return 'abstract'".  "abstract" is Java's way of saying that
the method is declared but not defined in the given class (the "abstract
class"), and therefore must be defined in the actual subclass that is
instantiated.  You cannot instantiate an abstract class (the only kind of
class that can have abstract methods).

This is a fundamental Java concept.  You should keep studying the tutorials.

> Read this
> <http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html>
> or some Java textbook.

Read the rest of the tutorials, too.

Signature

Lew

Roedy Green - 05 Sep 2007 05:00 GMT
>I don't quite understand how to use this method since I don't
>understand what the 'abstract' keyword means.

It returns an int, not abstract.  You can't use this method directly,
just some the method of the same name and signature that overrides it
and implements it. See http://mindprod.com/jgloss/abstract.html

Quite often only the abstract method is documented and some factory
gives you a class with that method, but that class itself is never
documented, just that it is as subclass of the abstract class
containing the method.
u
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

ChrisW - 05 Sep 2007 09:49 GMT
Thanks for the replies.  I'll go and try and understand the links
(hopefully they'll make more sense than some of the books I've been
reading).  I did do Java at uni, but it got taught so badly (to the
extent that official complaints were made to the head of department)
that not only did I not understand anything that was taught, but since
then, in the last 2 years, I've had to un-teach and re-teach myself
from scratch.  I can cope with procedural programming, but without
having anyone to advise me on the OO stuff, I've keep coming to dead-
ends.  It's just that this little problem (and Swing, which I think
I'm going to have to try and conquer in the near future) seem to
implicitly require an understanding of OO, in the way that everything
I've done procedurally doesn't.
Patricia Shanahan - 05 Sep 2007 17:36 GMT
> Thanks for the replies.  I'll go and try and understand the links
> (hopefully they'll make more sense than some of the books I've been
[quoted text clipped - 8 lines]
> implicitly require an understanding of OO, in the way that everything
> I've done procedurally doesn't.

Given your stated background, it may be better to pick one Java book you
like reasonably well, and read it from cover to cover doing the
exercises. Some sections will go fast, because you already have the
procedural aspects. You should still read them, because the author may
be planting ideas and terminology that will help you understand the OO
aspects.

Patricia


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.