Wikipedia:Reference desk/Archives/Computing/2010 September 22
Computing desk | ||
---|---|---|
< September 21 | << Aug | September | Oct >> | September 23 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
September 22
editPhysical Address Extension motherboards
editAccording to the Physical Address Extension article, the Linux kernel first supported PAE in version 2.3.23, which, according to a source, was released on October 22, 1999. Can you show me a motherboard that can accept x86 processor AND more than 4 GB of RAM, in 1999? As far as I can tell, I've never seen such a motherboard in any computer magazine (much less in the real world). However, there must be one such motherboard, since at least the kernel developers must use it to test the feature. Many thanks. 118.96.154.134 (talk) 08:00, 22 September 2010 (UTC)
- (Edit EC with below) From this quick search [1] - [2] and [3]. Searching for those chipsets should find more info. E.g. [4] & [5] (from 1997!) Whether it was possible to populate these motherboards with 8GB of RAM I don't know but clearly motherboards supporting 8GB of RAM did exist. If you look in the search results, there are discussions in 1999 of 8GB or more systems in the real world, e.g. [6] [7] [8] (16GB with support of up to 32GB) so whether with those chipsets or others, it was clearly possible. Of course Intel and other manufacturers do commonly provide early samples and reference boards to developers even before those products become available. BTW, what sort of "computer magazines" are you referring to? From my experience consumer computer magazine don't give much coverage to such high end stuff that is so way beyond what their audience can afford that it's of little interest, for example the stuff Rocketshiporion keeps asking us about. I guess there are probably some HPC magazines which may discuss these. Nil Einne (talk) 08:20, 22 September 2010 (UTC)
(ec) Many kernel developers have access to proprietary hardware and software systems long before it reaches the open consumer market (and the free software community at large). For example, IBM has invested heavily in Linux development and maintains an active team of kernel developers called the IBM Linux Technology Center. As such, they might have had access to internal hardware projects long before it ever reached the open consumer market. Similar large companies and hardware developers also maintain teams of kernel programmers; much of this development work becomes the GPL-licensed Linux kernel material we see at kernel.org. Nimur (talk) 08:22, 22 September 2010 (UTC)
- Thank you for the answers. After searching the Internet for more information, it appears that such a motherboard did indeed exist back then. Although quite different from typical motherboards at the time, it still accepts Pentium II Xeon processor (which is x86 processor) and, most importantly, more than 4 GB (i.e., up to 8 GB) of EDO DRAM.
- As to what kind of computer magazines do I read, it is precisely what you stated: general computer magazines. However, because I don't know that general computer magazines don't usually carry news about such an expensive motherboard (and because I don't know of any "HPC computer magazine"), I incorrectly assumed, until I asked this question that is, that such a motherboard don't really exist in physical form, but is instead "emulated", complete with its "x86 processor", by a mainframe's "virtual machine system" when configured to run an x86 operating system!
- 118.96.154.134 (talk) 12:01, 22 September 2010 (UTC)
Computer program illegal operation
editI was using my computer today when everything crashed and it said I had performed an "illegal operation". I was just writing an email, how is that illegal? Am I in trouble with the police? —Preceding unsigned comment added by K. R. Freeman (talk • contribs) 09:18, 22 September 2010 (UTC)
- In computing, an illegal operation refers to an operation which is not permitted by the application which is being run. It has nothing to do with the police and/or law of any country. So relax, you are not in trouble with the law. Rocketshiporion♫ 09:25, 22 September 2010 (UTC)
- Read "illegal" as "incorrect." Your computer had a technical error - it performed an "incorrect" operation. We might be able to help you identify exactly what broke if you tell us more specifically what the error-message said. Nimur (talk) 09:27, 22 September 2010 (UTC)
- (ec) "Illegal Operation" has nothing to do with the law of your country. Instead, much as an illegal pass in football is against the laws of the game, your computer's operating system places rules on what programs can and can not do, normally to stop a program from interfering with another program, or the operating system itself.. The program tried to something that the operating system forbade. If you can repeatedly reproduce the crash, then the program has a bug in it, and you might want to report it to the program's authors. CS Miller (talk) 09:35, 22 September 2010 (UTC)
- Apparently this error message confuses a lot of people. This is the danger of displaying jargon to the user in a way that expects them to understand it. Paul (Stansifer) 13:49, 22 September 2010 (UTC)
- If that causes such confusion, I sure hope all those internal debug messages about dying and killing (processes, that is) never make it to end users' eyes. JIP | Talk 16:11, 22 September 2010 (UTC)
- Apparently this error message confuses a lot of people. This is the danger of displaying jargon to the user in a way that expects them to understand it. Paul (Stansifer) 13:49, 22 September 2010 (UTC)
- You must be using a very old version of Windows. As mentioned at General protection fault#Behaviour in specific operating systems, that error message was last used in Windows 98. -- BenRG (talk) 20:05, 22 September 2010 (UTC)
- I've changed the title as "computer" isn't really distinguishing on a computing & IT board. CS Miller (talk) 09:35, 22 September 2010 (UTC)
- I believe that contradicts the no changing names unless there is no section title. Sir Stupidity (talk) 10:06, 22 September 2010 (UTC)
- As per Wikipedia:Reference_desk/Guidelines#Don't_edit_others'_questions_or_answers You may also add to a non-descriptive title (such as "question"), but it is best to keep the riginal title as a portion of the new one, as it may be used by the questioner to find the question, I thought that the OP's original title was not descriptive, thus I clarified the title. CS Miller (talk) 10:23, 22 September 2010 (UTC)
- Your point has been taken, Sir Stupidity (talk) 10:27, 22 September 2010 (UTC)
- As per Wikipedia:Reference_desk/Guidelines#Don't_edit_others'_questions_or_answers You may also add to a non-descriptive title (such as "question"), but it is best to keep the riginal title as a portion of the new one, as it may be used by the questioner to find the question, I thought that the OP's original title was not descriptive, thus I clarified the title. CS Miller (talk) 10:23, 22 September 2010 (UTC)
most bang-for-buck RAM in a hard-drive case?
editso obviously the interconnect between ram banks and cpu will be much faster than through the SATA or whatever (PATA, SAS, SCSI, FC, USB) hard-drive interface. So it seems to me it is much cheaper for a company to build a hard-drive case that just has to support these slower standards and has a ton of memory banks in it (like 48 of them). So, my two-fold question: do such CHEAP hard-drive enclosures supporting memory banks exist? And, if so, and if you don't really care about the kind of RAM/perforamce (just as long as it's not down to hard-drive latencies!), then what is the cheapest such solution? Is it competitive with the same number of gigabytes in a flash hard-drive? Thank you. 92.230.232.68 (talk) 12:28, 22 September 2010 (UTC)
- I don't understand what problem such a device would solve. Taking RAM (which is always expensive) and deliberately making it slow like this doesn't seem to serve any purpose. If you want lots of RAM, you'd run a 64 bit OS on a motherboard with support for lots of RAM, and just install it there. If you want lots of storage, you'd use flash or real hard disks, which are much cheaper. The only circumstances where you generally get external RAM is where it's serving as a cache for a something else; NetApp boxes have tons of RAM, but it's all cache for their disk arrays. -- Finlay McWalter ☻ Talk 12:38, 22 September 2010 (UTC)
- OP here. I priced a server with 192 GB of RAM (above, actually) and it was $150k. If I just need it for fast cache, surely I could buy some hard drive cases that take RAM, make an array of them, and fill them with better bang for the buck dimms than the 8 gb modules required for the aforementioned server? Or can't I? —Preceding unsigned comment added by 93.186.23.237 (talk) 14:07, 22 September 2010 (UTC)
- The issue is the bandwidth of the bus. Consider SATA 2 (the numbers are all in the same ballpark for different current busses); neglecting issues of encoding, that's a 3Gbit/sec bus, or about 300Mbytes/sec. The cheap, year old Seagate Barracuda in my machine here gets conservatively 100Mbytes/sec of read throughput. So three such disks are enough to saturate the SATA-2 bus. Looking at Tiger Direct, I can get a single 2TB disk for $110, so three will come to $330. So that's 6000 GB for $330, or 5 cents per GB. Now consider RAM - 1 GB costs around $25 -
50000[500] times more expensive. The hard disk version is just a fast, as the choke point is the bus bandwidth. Now maybe you can find components a bit cheaper than I have, and for writes you'd need a couple more disks to saturate the bus (as hard disks tend to be a bit slower at writing), but the fundamental point is the same - RAM is expensive because it's fast ; putting it at the end of a slow bus makes it slow, but doesn't make it cheap. -- Finlay McWalter ☻ Talk 15:29, 22 September 2010 (UTC)
- The issue is the bandwidth of the bus. Consider SATA 2 (the numbers are all in the same ballpark for different current busses); neglecting issues of encoding, that's a 3Gbit/sec bus, or about 300Mbytes/sec. The cheap, year old Seagate Barracuda in my machine here gets conservatively 100Mbytes/sec of read throughput. So three such disks are enough to saturate the SATA-2 bus. Looking at Tiger Direct, I can get a single 2TB disk for $110, so three will come to $330. So that's 6000 GB for $330, or 5 cents per GB. Now consider RAM - 1 GB costs around $25 -
- (Strictly, the RAM solution will have quite a bit less latency than the hard disks, but you'd really have to care a lot about latency, and have a particularly random-y access pattern, to accept a solution tens of thousands of times more expensive than the disks. -- Finlay McWalter ☻ Talk 15:36, 22 September 2010 (UTC)
- (EC with above) DRAM based SSDs do exist, and have for quite a while. They are described briefly at Solid-state drive#DRAM based drive (although that section is rather brief, for example it includes a picture of a RamSan device [9] but no mention or discussion). Before flash RAM SSDs took off they were the only option, but I think flash SSDs are now generally the better option in most areas. Likely to be even more true if your talking about SATA let alone PATA etc given the interface limitations.
- I have heard of some devices with a small number of slots 4-8, the article mentions some. And you can get things like the RamSan which support lots of RAM (up to 512GB). But if you look in the whitepaper for the RamSan 440 (seems to be broken on their server but still available [10]) it appears to use special memory boards. I also note the RamSan 440 is from either 2008 or early 2009, I wonder if they too are abanding DRAM. Sun have their high performance flash devices [11].
- As per my earlier comment, you may notice most of these devices use often several fibre channels, or PCI-express or something rather then SATA (let alone PATA).
- BTW, I don't think making a device capable of supporting 96 random commodity/off the shelf non registered RAM DIMMS is easy as you seem to think. And for most people interested in such devices, having something which is reliable and stabile is likely important, for example ECC which you don't seem to care about is something many probably do care about. Space and power usage may also matter.
- Nil Einne (talk) 15:55, 22 September 2010 (UTC)
- So, if all you want is a big chunk of "memory", that you don't care much about its speed, but you like the convenience of a programming model where everything appears to be in RAM, then you'd do the following: you'd get a modestly priced external storage array (say SCSI or ESATA) with say 4 or 8 disks in it). You'd configure that for RAID 0 (because you don't care about data integrity or uptime), you'd install a 64 bit OS (which will give you an address space far far greater than the RAID), and you'd memory map the disk into your OS's address space. If you really wanted you could wrap that with a specific malloc call (or the equivalent for the internals of a dynamic language like C# or Java); it'd sure be wise to have a special slow_malloc() call rather than overriding the main system malloc, but that's up to you. With that, you can treat that disk array as if it was a big, hugely-expensive chunk of RAM, and only the slow performance will give it away. -- Finlay McWalter ☻ Talk 16:01, 22 September 2010 (UTC)
- I don't think that's economical to do, due to the following reasons:
- older (and slower) memory modules are actually more expensive than newer (and faster) modules, and
- the cheapest (newer) modules are still expensive and you'll waste a lot of bandwidth by communicating with it using the SATA interface.
- 118.96.154.134 (talk) 16:02, 22 September 2010 (UTC)
- I don't think that's economical to do, due to the following reasons:
- Actually, $25 per gigabyte is 500 (five hundred) times as expensive as 5 cents per gigabyte, not 50000 (fifty thousand) times as expensive. JIP | Talk 16:08, 22 September 2010 (UTC)
- D'oh, silly me. -- Finlay McWalter ☻ Talk 16:33, 22 September 2010 (UTC)
- I corrected the original, I hope you don't mind. Also I'm the OP here. You said: now consider RAM - 1 GB costs around $25. That's $250 for 10 GB, $2,500 for 100 GB. (Or 25k for a terabyte). Let's stick with 100 GB for now. The reason I want that at the end of a hard-drive bus is PRECISELY for random reads of any part of the data set, orders of magnitude faster than waiting for the hard-drive head to move there, and random enough that it doesn't help to cache. Now, the question is: How much do I have to pay to put that $2500 worth of 1 GB ram into the end of a SATA connection. Anyone? 92.230.232.68 (talk) 16:52, 22 September 2010 (UTC)
- You would have to pay well over $2500 for the hardware that would convert that RAM into a storage medium. I have seen PCI-express cards that use RAM as a cache for stuff like photoshop, but they are usually over $1000 and only support a few DIMMs. Try to imagine having 100 slots for RAM inside your computer (or in a box outside it more likely), and then imagine the ~250 volts that RAM would use, and the massive amount of cooling that would require. A high end SSD would already nearly saturate the bandwidth available on SATA and can be found for under $1000. 206.131.39.6 (talk) 18:57, 22 September 2010 (UTC)
- Correction: a SATA "drive" supporting up to 64GB of RAM costs about $350. You would have to consider the cost of eight 8GB DIMMs on top of that though. 206.131.39.6 (talk) 19:04, 22 September 2010 (UTC)
- What kind of problem requires so many random reads? Few tasks inherently have so little locality that the memory hierarchy doesn't work on them. Paul (Stansifer) 14:30, 23 September 2010 (UTC)
- Products like the OCZ Vertex 2 [12] solid state drive, offer 120 GB for about $300, and effectively saturate the 3 Gbit/s bus during sustained reads and writes. [13] You are unlikely to do any better than that with a custom DRAM solution if it is limited to an SATA interface. You can do incrementally better by moving to 6 GBit/s SATA or a PCI-e interface, but only by a factor of a few in speed. The current generation of solid state drives are already (relatively) affordable and have basically reached the limits of what a single 3 Gbit SATA channel can support. Dragons flight (talk) 21:28, 22 September 2010 (UTC)
- If your requirements are for random reads of a given data set at very low latency, I would recommend the RamSan-10 / RamSan-20, which have 225GiB and 450GiB of nett capacity respectively. These are x4 PCIe 2.0 SLC SSDs, and they plug directly into the motherboard. According to the Texas Memory Systems' website, these have a maximum 700MB/s throughput, support up to 120,000 IOPS and consume 15 watts. But be warned that the RamSan-10 is priced at $11,000 and the RamSan-20 costs $18,000. Rocketshiporion♫ 06:19, 23 September 2010 (UTC)
Spaces in a path variable in a shell script on OS X
editI'm attempting to write a shell script, but running into a problem with spaces in a variable name. The code:
path="/Users/grey/oh\ no\ there\ are\ spaces/"
grep -ilr "lorem" $path | echo
returns an error because of the spaces. I thought that \ was the appropriate way to mark out spaces, but apparently not. Any ideas? --CGPGrey (talk) 16:26, 22 September 2010 (UTC)
- grep -ilr "lorem" "$path" | echo should work -- Finlay McWalter ☻ Talk 16:32, 22 September 2010 (UTC)
- Sadly it does not. This is the output:
grep: /Users/grey/oh\: No such file or directory
grep: no\: No such file or directory
grep: there\: No such file or directory
grep: are\: No such file or directory
grep: spaces/: No such file or directory
--CGPGrey (talk) 16:38, 22 September 2010 (UTC)
- (First, don't pipe to echo. That loses your output!) There are two separate issues here:
- Spaces separate words. There are three ways to suppress that: "", '', and \. All of these are equivalent:
grep -ilr lorem "/Users/grey/oh no there are spaces/"
grep -ilr lorem '/Users/grey/oh no there are spaces/'
grep -ilr lorem /Users/grey/oh\ no\ there\ are\ spaces/
- As you might guess,
"its and it's"
and'a "valuable" opportunity'
are valid: each kind of quotes can contain the other. (They interact oddly and differently with ! and \, so be careful and/or read the manual.)- Separately, you need "" (specifically) when you use a variable that might contain spaces because variable substitution happens before word splitting (look for "seven"):
$ file=with\ space
$ touch "$file"
$ ls "$file" # you can also use things like "$file.bak" or "new/$file"
with space
$ ls '$file' # single quotes don't expand variables
ls: cannot access $file: No such file or directory
$ ls $file
ls: cannot access with: No such file or directory
ls: cannot access space: No such file or directory
- The bash man page (that I linked) is really quite good, if long. I recommend it as a reference. See also variable interpolation. --Tardis (talk) 16:46, 22 September 2010 (UTC)
- Thanks so much. The "$path" trick worked perfectly, but now that raises one more spaces-related problem that I can't quite work out. Here is the code that the above is getting worked in to:
path="/Users/grey/oh no there are spaces/"
for file in $(grep -ilr "lorem" "$path")
do
echo "$file"
done
But the file names that I'm trying to echo also have spaces in them -- thus screwing up the output like so:
$ /Users/grey/oh no there are spaces/
some
folder/file.txt
Any more help would be appreciated. --CGPGrey 17:22, 22 September 2010 (UTC) —Preceding unsigned comment added by CGPGrey (talk • contribs)
- Quote the grep result:
path="/Users/grey/oh no there are spaces/"
for file in "$(grep -ilr lorem "$path")"
do
echo "$file"
done
- —Emil J. 17:46, 22 September 2010 (UTC)
- This can't handle more than one file, because the "" suppresses all separation of the output from grep. If you're willing to assume that your filenames contain no newlines, you can do something like
grep -l ... | while read; do
echo "$REPLY"
done
- but the real answer is to not use the shell at all for this part and use
grep -lZ ... | xargs -0 ...
. - It's also worth noting that this is why to use
$()
rather than``
for command substitution. Handling the nested "" or `` inside backticks is tricky. --Tardis (talk) 18:27, 22 September 2010 (UTC)
- but the real answer is to not use the shell at all for this part and use
Landing page
editI would like to know that a landing page for a membership website is a good idea for SEO or not.Can you please give reasons for it. —Preceding unsigned comment added by 75.1.36.10 (talk) 18:14, 22 September 2010 (UTC)
- What sort of membership website have you in mind? These tipsare business-oriented, but might help. Have you read our article on Search engine optimization? Dbfirs 11:59, 24 September 2010 (UTC)
UHDTV - 8k resolution
editI wanted to know why in UHDTV, although we call it 8k, the resolution is 7680 X 4320 which is Horizontally only 7.5 times 1k (1024) and why it isn't 8192 X 4320. While that of 4k is 4096 X 2160. I understand that 7680 is 4 times (horizontally and vertically) the HDTV standard of 1920 X 1080. -Ananth (talk)
um, for resolution if someone told me "k", I would understand thousand, not 1024. Only if you were talking about bandwidth would that thought even come up. Did you think "megapixel" means 1024x1024 pixels or one million pixels? 92.230.232.68 (talk) 20:32, 22 September 2010 (UTC)
- As you said yourself, UHDTV is a TV format, and is exactly 4 times the resolution (in each direction) of HDTV. That's why it's horizontal resolution is 7680. I guess some people call it 8k since there is a film standard called 8k and this TV standard is close to it. --Phil Holmes (talk) 10:15, 23 September 2010 (UTC)
- In this case, I'd like to ask then why is 4k format given at 4096 X 2160 and digital cinema 2048 X 1080. I also see the aspect ratio for the 2k, 4k and 8k is closer to 17:9 than the 16:9. Thanks for the comments, but further help will be appreciated.-Ananth (talk)
Digital broadcast TV in Ireland
editAfter resolving my tv tuner problem from above, I've a new question. The tuner I ended up with was a dual analogue/digital hybrid. I live in Dublin. I had been led to believe that there wasn't yet digital tv broadcast in Ireland. I also learned that part of the standard that was going to be used in Ireland was Mpeg4 as opposed to the UK's Mpeg2. As far as I can tell (from the box & googling) my card only supports Mpeg2 (WinTV-HVR-1100 (model 1103)). Can anyone explain how come I'm picking up digital Irish channels on my pc via my aerial? Stanstaple (talk) 19:50, 22 September 2010 (UTC)
- There's no such thing as a DVB-T card only supporting MPEG2, since the card doesn't care what codec is used (well unless it has hardware decoding, although even then you could still likely use software decoding and I'm not aware of any DVB-T card with hardware decoding). If Ireland is going to use DVB-T, then any DVB-T card should work if the software supports it. Here in NZ, as in a number of other countries we use H264 and AAC, both of these caused problems at first (the video particularly the interlaced variant, the audio because we were using LATM I believe), but quite a few software solutions now work fine. A number of European countries had similar problems I believe. Of course even if the software doesn't support it, you still should be able to record the any mux or parts thereof, it's just that you can't play it back. In the UK, I believe they plan to use DVB-T2 with H264 for their HD terrestrial, if they use DVB-T2 in Ireland as well then a DVB-T card obviously won't work. Nil Einne (talk) 23:54, 22 September 2010 (UTC)
- There's some more info about that at Freeview (UK)#Freeview HD, which says it's H.264/MPEG-4 AVC with audio encoded as AAC or DD+. Ideally the Republic would skip directly to DVB-T2, but right now there isn't that much Freeview-HD compatible equipment available for sale in the UK (which I assume means most manufacturers aren't making it yet). -- Finlay McWalter ☻ Talk 14:54, 23 September 2010 (UTC)
- Online information about the actual state of DVB-T broadcast in the Republic is almost non-existent. DCENR promises 90% of the population will be able to receive RTE's DTV service by the end of October 2010 (ref). Television in Ireland#Digital terrestrial television says "publicly accessible tests of this system are available across large swathes of the country as of December 2009, with it being carried on all main and some relay transmitters." - so that's what you've been seeing. DCENR also says says the Republic is still committed to meeting the EU-wide mandate of switching off analog TV by the end of 2012. I'd be very impressed if the Republic manages that; the UK plans switchoff at the same time, which will be 14 years after ITV Digital began, and 10 after it switched to Freeview, and still those areas of the UK which have had trial switchoff have needed quite a lot of handholding and subsidy, particularly for elderly folk. For the Republic to make the same transition in only 2 years, at a time when people who don't have compatible TVs are going to be particularly disinclined to change them or buy additional equipment - that seems like a tall order. What I really don't understand is why the Republic is so far behind - looking at List of digital television deployments by country shows all kinds of countries far less prosperous than Ireland (like say Albania) switching DTT on years ago). -- Finlay McWalter ☻ Talk 14:27, 23 September 2010 (UTC)
- Thanks for the info & links lads. I had hoped that the mpegX issue would be software rather than hardware related but it's nice to be reassured by people who know about what they're talking about. I'm using media center to watch tv and I assume MS will continue to support a standard used in a European country, so hopefully that won't be an issue for me. I'm surprised (perhaps naively) that there hasn't been more public information about the fact that digital broadcast tv is available in the Republic. Do you reckon it's safe to assume that if I can receive and watch digital broadcast tv now, I'll still be able to do so when it 'goes live'? Is it at all likely that a change will be made to the system that means I'll be out of luck? As to why Ireland is lagging so far behind,- I'm at risk of soaping if I attempt to address that :) Stanstaple (talk) 19:49, 24 September 2010 (UTC)
- "Going live" probably just means telling people about it (which if Ireland is anything like the UK means incessant ads hosted by a chirpy character so annoying you'll want to sell your TV and move to a remote monastery where electricity is forbidden). If it's not officially "live" they can occasionally turn it off to fix things without having to deal with angry letters. A smallish market like the Republic can't afford to go with some weird special technological standard of its own (both broadcast and reception equipment really has to come off-the-shelf), so you can bet that things will work in the future as they do now. -- Finlay McWalter ☻ Talk 21:30, 24 September 2010 (UTC)
cannot access ExtendedReader, duplicate class: extra.ExtendedReader
editCould you please help me solve these java errors?
TextEdit.java, line 38, "cannot access ExtendedReader":
Extended content
|
---|
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import extra.*;
class TextEdit extends Frame implements ActionListener{
Panel p = new Panel();
TextField name = new TextField();
Button open = new Button("Open");
Button save = new Button("Save");
Button exit = new Button("Exit");
TextArea area = new TextArea(10,60);
TextEdit()
{
p.setFont(new Font("SansSerif", Font.PLAIN, 12));
area.setFont(new Font("Monospaced", Font.PLAIN, 12));
p.setLayout(new GridLayout(1,5));
p.add(name);p.add(open);p.add(save);p.add(exit);
name.addActionListener(this);
open.addActionListener(this);
save.addActionListener(this);
exit.addActionListener(this);
setLayout(new BorderLayout());
add("North", p);
add("Center", area);
pack();
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==name ||e.getSource()==open) readFile(name.getText());
else if (e.getSource()==save) saveFile(name.getText());
else if (e.getSource()==exit) System.exit(0);
}
void readFile(String name)
{
area.setText("");
ExtendedReader inFile = ExtendedReader.getFileReader(name);
if(inFile==null)
{
Toolkit.getDefaultToolkit().beep();
return;
}
String s;
while((s=inFile.readLine())!=null) area.append(s+"\n");
inFile.close();
}
void saveFile(String name)
{
ExtendedWriter outFile = ExtendedWriter.getFileWriter(name);
outFile.print(area.getText());
outFile.close();
}
public static void main(String[] arg)
{
TextEdit t = new TextEdit();
}
}
ExtendedReader.java, line 6, "duplicate class: extra.ExtendedReader": package extra;
import java.io.*;
import java.text.*;
import java.util.*;
public class ExtendedReader extends BufferedReader {
// texts for error messages
private String illegalInt;
private String illegalNum;
private String eofText;
private NumberFormat nf;
// constructors
public ExtendedReader (Reader r) {
super(r);
setFormat(NumberFormat.getInstance());
setLang(Locale.getDefault().getLanguage());
}
public ExtendedReader (Reader r, int bufferSize) {
super(r, bufferSize);
setFormat(NumberFormat.getInstance());
setLang(Locale.getDefault().getLanguage()); }
// private instance methods
private void flush() {
if (this == Std.in)
Std.out.flush();
}
private static void abort(String message) {
Std.err.println(); Std.err.println();
Std.err.println(message);
System.exit(1);
}
// public static methods
public static ExtendedReader getFileReader(String fileName) {
try {
return new ExtendedReader(new FileReader(fileName));
}
catch (FileNotFoundException e) {
return null;
}
}
// public instance methods
public int readChar() {
try {
flush();
return read(); // returns -1 at end of file
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return 0; // will never get here
}
public int lookAhead() {
try {
flush();
mark(2);
int i = read();
if (i != -1)
reset();
return i; // returns -1 at end of file
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return 0; // will never get here
}
public long skip(long n) { // returns the number of skipped characters
flush();
try {
return super.skip(n);
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return 0; // will never get here
}
public void skipLine() {
flush();
try {
int c;
while ((c = read()) != -1 && c != '\r' && c != '\n')
;
if (c == '\r' && lookAhead() == '\n') // MS-DOS
skip(1);
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
public boolean more() { // skips blanks, gives false at end of file
int c;
while ((c = lookAhead()) == ' ' ||
c == '\t' || c == '\r' || c == '\n')
skip(1);
return c != -1;
}
public String readLine() {
try {
flush();
return super.readLine(); // returns null at end of file
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
return null; // will never get here
}
public String readWord() {
if (more()) {
String s = "";
int c;
while ((c = lookAhead()) != -1 && c != ' ' &&
c != '\t' && c != '\r' && c != '\n')
s = s + (char) readChar();
return s;
}
return null;
}
public Number readNumber(String errMess) {
// returns null at end of file
while (true) {
String s = readWord();
if (s == null) // end of file
return null;
ParsePosition pos = new ParsePosition(0);
Number n = nf.parse(s, pos);
if (n != null && pos.getIndex() == s.length())
return n;
else {
skipLine();
Std.err.println(errMess);
}
}
}
public int readInt() {
nf.setParseIntegerOnly(true);
Number n = readNumber(illegalInt);
nf.setParseIntegerOnly(false);
if (n == null)
abort(eofText+"readInt");
return n.intValue();
}
public long readLong() {
nf.setParseIntegerOnly(true);
Number n = readNumber(illegalInt);
nf.setParseIntegerOnly(false);
if (n == null)
abort(eofText+"readLong");
return n.longValue();
}
public double readDouble() {
Number n = readNumber(illegalNum);
if (n == null)
abort(eofText+"readDouble");
return n.doubleValue();
}
public void close() {
try {
super.close();
}
catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
public void setFormat(NumberFormat f) {
nf = (NumberFormat) f.clone();
nf.setGroupingUsed(false);
}
public NumberFormat getFormat() {
return nf;
}
public void setLang(String lang) {
// initilize texts for error messages
if (lang.equals("sv")) { // Swedish
illegalInt = "Felaktigt heltal. Fˆrsˆk igen";
illegalNum = "Felaktigt tal. Fˆrsˆk igen";
eofText = "Filslut i metoden ";
}
// or whatever language you wish ...
else { // English default
illegalInt = "Illegal whole number. Try again";
illegalNum = "Illegal number. Try again";
eofText = "End of file in ";
}
}
}
|
115.178.29.142 (talk) 23:22, 22 September 2010 (UTC)
- The problem seems to be in something besides what you've posted. The "duplicate class" error message indicates there is something else the compiler recognizes as "extra.ExtendedReader", but it is not here. I can put your posted source into my own environment, comment out references to other things that are not here (like Std and ExtendedWriter) and it compiles fine.
- You might find it if you search your entire source for "ExtendedReader" and discover where else you have this name. Without knowing everything you've got in these directories, it is difficult to diagnose things further.